Method and apparatus for data flow analysis

ABSTRACT

A computer system for executing a binary image conversion system which converts instructions from a instruction set of a first, non native computer system to a second, different, native computer system, includes an run-time system which in response to a non-native image of an application program written for a non-native instruction set provides an native instruction or a native instruction routine. The run-time system collects profile data in response to execution of the native instructions to determine execution characteristics of the non-native instruction. Thereafter, the non-native instructions and the profile statistics are fed to a binary translator operating in a background mode and which is responsive to the profile data generated by the run-time system to form a translated native image. The run-time system and the binary translator are under the control of a server process. The non-native image is executed in two different enviroments with first portion executed as an interpreted image and remaining portions as a translated image. The run-time system includes an interpreter which is capable of handling condition codes corresponding to the non-native architecute. A technique is also provided to jacket calls between the two execution enviroments and to support object based services. Preferred techniques are also provide to determine interprocedural translation units. Further, intermixed translation/optimization techniques are discussed.

BACKGROUND OF THE INVENTION

This invention relates generally to binary translation and compilationof source code for use in computer systems and more particularly to dataflow analysis in translation and compiliation systems.

As it is known in the art, computer systems which generally include acentral processing unit (CPU), a main memory, and an input-output deviceinterconnected by a system bus are used to execute computer programs toperform a useful task. One type of computer program is an operatingsystem which is used to interface the CPU to an application program. Theaforementioned application program is used by a user of the computersystem to perform the useful task.

The operating system includes the software resources needed by thecomputer system to interface hardware elements to the computer system aswell as to interface the application program and other programs to thecomputer system.

Application programs typically include programs, such as wordprocessors, which execute on the computer system under the control ofthe operating system. One technique commonly used to produce a binaryimage includes compiling source code written in a programming languageto produce object code. The object code is typically linked with alinker to produce the binary image. Another technique is to convert aexecutable image of an application program for execution in a computersystem of a first computer architecture into a executable for adifferent computer architecture. Generally, without some conversionbinary images made for one particular architecture and operating systemcannot execute on a different architecture and/or operating system.

A compiler generally includes a front end which converts the source codeinto an intermediate representation and a back end which for exampleoptimizes the intermediate language representation to permit theproduction of efficient object code. Data flow analysis is typicallyperformed as part of the optimizations. In a complier a routine isgenerally used as the basic unit upon which data flow analysis isperformed.

Optimizers included in existing binary translators that perform dataflow analysis typically perform such analysis using a basic block,rather than a routine. A basic block is generally defined as one or moreintermediate language statements with no embeded control flow, e.g., nointervening entry or exit point. A routine generally comprises manybasic blocks. An optimizer in binary translator generally uses the basicblock as the unit of optimization processing due to the lack of programstructure in the binary image.

Generally, data flow analysis examines a flow graph representation of acomputer program determining the state of the computer program, forexample, the value of a program variable, at different points in aoptimizable unit of the program. The possible execution control flowpaths that comprise the unit are examined and typically, information isgathered about what can be true at various points in paths of the flowgraph. For example, the values of a program variable are determined foreach different possible execution path in the computer program. If dataflow analysis indicates that a program variable is never used or read ina computer program, that variable and its associated storage cantypically be eliminated.

One problem encountered in performing data flow analysis in compilers ishow to represent the results of the analysis in a manner which affordsefficient use of computer system resources, such as an organization ofthe analysis information that minimizes storage requirements while theorganization also affords efficient retrieval of the analysisinformation.

A problem also encountered in performing data flow analysis in binarytranslation, as with compilers as previously discussed, is how torepresent the results of the analysis in a manner which affordsefficient use of computer system resources.

Techniques currently used by compilers in storing and retrieving dataflow analysis information generally have problems with efficiency andare not readily scalable to larger programs without introducingundesirable restrictions and drawbacks.

One common mechanism used to represent data flow analysis information inan optimizing compiler includes using a first technique for representingglobal data flow information and a second, different technique forrepresenting local data flow information.

One way in which compilers typically represent global data flow analysisinformation is a “dense” representation, such as using bit vectors torepresent summary results of data flow analysis. Generally, multiple bitvectors are associated with each basic block to represent globalinformation about the basic block with respect to other basic blocks. Aposition in a bit vector is reserved for each data item. For example, arepresentation of the data flow analysis information associates two (2)bit vectors representing global data flow analysis information with eachbasic block. A first bit vector (GEN) has a bit corresponding to eachdata item that is known to at least one other basic block. A bit is setwithin GEN if the corresponding data item is defined within the basicblock. A second bit vector (USE) also contains a bit corresponding toeach data item known to at least one other basic block. A bit is setwithin USE if there is an upwardly exposed use of the corresponding dataitem within the basic block. That is, the bit is set if the datadefinition within the basic block depends on another data definitionoutside of the basic block.

This dense representation of data flow analysis information tends to becomputationally inefficient when gathering information needed to performoptimizations and expensive in terms of execution time and storage. Alarge fixed amount of storage is required. In reference to the previousexample of representing global information using two (2) bit vectors perbasic block, if there are “N” data items and “M” basic blocks, the fixedstorage cost for only global information is the product of (“N”* “M”*2).In computational complexity terms, the storage cost is of order O(n²).This technique is generally not scaleable since, as routines andprograms become larger, the fixed amount of storage tends to increase asa power of two (2).

As an improvement to reduce the amount of fixed storage needed, someimplementations have limited the data definitions that are trackedlocally and/or globally. For example, an implementation performs globaloptimizations upon only certain types of variables. This decreases theamount of storage required, but, does not provide direct or unifiedconnectivity with one information data structure. Additionally, thisimprovement adds the restriction of limiting the number and types ofdata definitions upon which optimizations can be performed.

Another drawback of the bit vector representation is that a bit vectoris not an information “rich” data structure. Bit vectors typicallyrepresent derived or summary information about a basic block. Not muchinformation can be recorded and retrieved from one bit of storage perdata item. For example, in performing an optimization using the globaldata flow information, it is necessary to locate the precise instructionor statement within the basic block that is defining the data item. Bitvectors do not capture this detailed information. Therefore, anothermechanism is needed to provide the more specific, detailed informationusually required about global data flow.

Typically, one of two techniques is used to obtain the additionaldetailed information associated with global data flow analysis. Onetechnique uses a subordinating data structure to represent the detailedinformation, for example, such as a pointer to the actual instructionthat performs a data item definition and a data item reference. A secondtechnique used is to locate the actual instruction(s) needed at aparticular instance during optimization by performing a sequentialsearch, for example, of instructions within a basic block.

In addition to the large amount of fixed storage typically needed inoptimization processing using bit vectors, another drawback of theforegoing representation for global data flow information is the lack ofdirect connectivity between basic blocks for data items havingsignificance that transcends a basic block, such as a data definition ina first basic block having a global reference in a second basic block.Direct connectivity affords efficient information retrieval. Forexample, given a global definition, when performing an optimization, theoptimizer needs to locate all references or data dependencies on thedata definition. A bit vector, like the USE vector previously described,is associated with each basic block. To determine all the neededreferences, the optimizer examines the USE bit vector of each basicblock to locate which basic blocks have dependencies. However, whenperforming optimizations such as constant propagation, the optimizeralso needs to know the actual statement or instruction as determinedusing one of the two techniques previously described for obtaining theadditional detailed information associated with global data flowanalysis.

Using either technique with the bit vector does not provide directconnectivity that includes, for example, direct connections from adefinition in one basic block to all references in other basic blocks.Such direct connectivity is desired to have an efficient propagation andretrieval of information since these are typically the most frequentactivities performed by an optimizer.

As previously mentioned, local data flow information is typicallyrepresented using a second technique different from the foregoing globaldata flow scheme. One common technique used to represent local data flowanalysis information includes building a directed graph comprising nodesand directed arrows or edges connecting the nodes. In oneimplementation, a node is a first code cell connected to another secondcode cell by a directed edge represented as a structure with a pointerconnecting the first and second codecells. The first code cellrepresents a data definition. The second code cell represents areference to the data definition. Frequently, an implementation of thedirected edge is doubly connected in that the second code cell is alsoconnected to the first code cell allowing the directed edge to betraversed in both directions, e.g., source to destination andvice-versa.

This directed graph for storing local data flow information provides adegree of direct connectivity, e.g., given a local data definition, theoptimizer can directly connect to all local references to the datadefinition. However, this does not provide direct connectivity to anyremaining global references, for example.

A drawback arises from using two different techniques for each of localand global data flow information rather than use a single technique forboth. The amount of computer resources, such as memory, to store theassociated code for building data flow information is generally greatersince a minimal amount of code is typically shared in an implementationof both the local and global data flow analysis. Having more codetypically increases associated development costs, such as additionaltesting. Adding functionality usually includes implementing anddebugging one routine for local data flow analysis and another differentroutine for global data flow analysis because they cannot share the sameroutine.

SUMMARY OF THE INVENTION

It would be desirable to have uniformity in the organization andretrieval of local and global data flow information for efficiency. Ifthere is similar structure, local and global data flow analysis phasescan have common access and maintenance routines which reducesdevelopment and maintenance costs and provides for more efficient use ofcomputer system resources.

Direct connectivity is desirable on both the local and global levels forefficient information retrieval for operations frequently performed bythe optimizer.

A reduction in the fixed amount of memory required to store data flowanalysis information is also desirable, particularly for large routines,routines with a large amount of global information, or for largeprograms when performing interprocedural optimizations. To require afixed amount of memory for performing optimizations may incur otherundesirable and unnecessary limits, such as limit the size of theprogram that can be optimized or use more system memory leaving lesssystem resources for other tasks. An incremental use of memory, ratherthan a fixed large amount of memory, is desirable. Generally, the dataflow analysis should incrementally use more memory if there are moredata definitions and data references.

It is also desirable to represent data flow analysis information in astructure that affords flexibility allowing an implementation tointerchange and trade off optimization execution time for storage space.Such flexibility may be needed due to the different optimizationsperformed or system resource requirements, such as limited amount ofsystem memory. A flexible representation of data flow analysisinformation allows an optimizer to trade off optimization execution timefor storage space or memory depending on, for example, the current needsof the optimization being performed upon a particular computer system.For example, an optimizer performs varied and numerous optimizationswherein each optimization has different fixed overhead requirements toperform the optimization. An optimization, such as constant propagationtypically requires a large amount of direct connectivity. Whenperforming the constant propagation optimization, an optimizer buildsthe data structures to obtain the direct connectivity thus incurring astorage cost. However, in performing the optimization, less runtimecosts are incurred. When performing an optimization in another computersystem with a lesser amount of memory, to obtain similar data flowinformation, an implementation may have to incur the increased runtimecosts and forego the increased storage.

When optimizing a binary image, a problem which arises is how todetermine a unit of translation larger than a basic block, such as aroutine, upon which optimization processing is performed when generallythe binary image lacks program structure. This lack of structure tendsto inhibit application of optimizations which generally produce moreefficient code. Assumptions as to content and property of a programcannot be made, and therefore, a program cannot be examined and analyzedfrom a broad perspective typically providing better optimizations.Generally, therefore, only small scale local optimizations within abasic block is typically performed using the basic block as theoptimization unit.

One approach is to determine a unit of translation analogous to aroutine by examining and recording runtime information duringinterpretation and execution of a binary image to formulate the unit oftranslation.

In accordance with the present invention is a method executed in acomputer system for performing local data flow analysis. The methodincludes performing local data flow analysis upon basic blocks in aroutine. Local analysis information is produced for each basic block.Using local analysis information, global data flow analysis isperformed. Global data flow analysis includes the step of determiningmerging definition points of a routine only when there is an upwardlyexposed data reference of a state container in a first basic block to adefinition of the state container in a second basic block.

In accordance with a further aspect of the invention is a memory forstoring data flow analysis information. The memory includes anintermediate representation of a routine, a state container, basic blockvalues, basic block state containers, and a global value definition of astate container defined within a first basic block and referenced in asecond basic block. The global data value definition is represented as afirst basic block value associated with a first basic block statecontainer. The reference to the global data value definition isrepresented as a second basic block value associated with a second basicblock state container. The first and second basic block state containersare associated with each other.

With such an arrangement, there is similarity in structure anduniformity in organization and retrieval of local and global data flowinformation. Common access and maintenance routines can be used in bothlocal and global data flow thereby reducing development costs andproviding more efficient use of computer resources.

The amount of memory for storing data flow analysis using the foregoingarrangement is scaleable and incremental, rather than a fixed largeamount of memory. The arrangement for storing and retrieving data flowanalysis information is flexible allowing an optimizer to trade offoptimization execution time for storage depending on the particularneeds of an optimization and computer system resources available.

BRIEF DESCRIPTION OF THE DRAWINGS

The foregoing features and other aspects of the invention will nowbecome apparent when the accompanying description is read in conjunctionwith the following drawings in which:

FIG. 1 is a block diagram of a computer system;

FIG. 2 is a block diagram of a dual stage instruction conversion systemincluding a run-time system and a background system;

FIG. 3 is a block diagram of the run-time system portion of theinstruction conversion system of FIG. 2;

FIG. 3A is a flow chart depicting the steps performed at run-time toexecute a non-native image on the system of FIG. 1;

FIG. 4 is a more detailed block diagram of a binary translator used inthe background system portion of the conversion system of FIG. 2;

FIG. 5 is block diagram of a data structure representing a profilerecord structure;

FIG. 6 is a block diagram of a representative profile record of theprofile record structure of FIG. 5;

FIG. 7 a diagram showing a typical arrangement for a instruction for acomplex instruction set computer (CISC);

FIG. 8 is block diagram of a register file in the computer system ofFIG. 1 showing assignment of registers corresponding to the non-nativearchitecture;

FIG. 9 is a diagram showing a typical construct for one of the registersin the register file of FIG. 8

FIG. 10 is a pictorial representation of connections of various datastructures including a dispatch table to determine an equivalent routinefor the interpreter;

FIG. 11 is a pictorial representation of the process for activating analternate dispatch table;

FIG. 12 is a diagram showing an arrangement of an entry from thedispatch table of FIG. 10;

FIG. 13 is diagram showing a typical arrangement of condition codes of aCISC architecture which implements condition codes;

FIG. 14 is a block diagram of an arrangement to determine evaluationroutines for condition codes;

FIG. 15 is a block diagram of an arrangement to determine evaluationroutines for current and previous values of condition codes;

FIGS. 16-18 are a series of diagrams useful in understanding howcondition codes are handled in the run-time system of FIG. 3;

FIGS. 19 and 20 are diagrams showing relationship between addressspaces;

FIG. 21 is a diagram of a context data structure used in the interpreterof FIG. 4;

FIG. 22 is a block diagram of a pair of data structures stored in memorywhich represents a return address stack for a non-native image of aprogram as well as shadow stack for a native image of the program;

FIG. 23 is a diagram showing the relationship between the datastructures of FIG. 22 and execution of non-native and native routineswith calls into corresponding non-native and native routines;

FIG. 24 is a diagram of a data structure including translated ornative-image routines and call address translation table;

FIG. 25 is a diagram depicting the relationship of the routine calltables in the translated image and the shadow stack to the on-line andbackground systems;

FIG. 26 is a flow diagram of a typical application program instructionsequence used to illustrate aspects of the invention;

FIG. 27 is a block diagram showing an example of an object;

FIG. 28 is a block diagram showing an example of cross process callingof object methods;

FIG. 29 is a block diagram showing an example of an interface structure;

FIG. 30 is a flow chart showing an example of steps leading to the useof an object in an object oriented service system;

FIG. 31 is a flow chart showing steps in an example embodiment of amethod for intercepting functions to perform interface structurereplacement;

FIG. 32 is a flow chart showing an example replacement interfacestructure;

FIG. 33 shows an example embodiment of a template for a jacket function;

FIG. 34 is a flow chart showing steps performed in an example embodimentof a PBJA jacket function when called from non-native code;

FIG. 35 is a flow chart showing steps performed by an example embodimentof a PBJA jacket function when called from native code;

FIG. 36 is a flow chart showing steps performed by an example embodimentof a PAJB jacket function when called from native code;

FIG. 37 is a flow chart showing steps performed by an example embodimentof a PAJB jacket function when called from non-native code;

FIG. 38 is a block diagram showing an example of a system for load timeprocessing to support interception of functions which take a pointer toan object as a parameter;

FIG. 39 is a flow chart showing an example of steps performed at runtime to support interception of functions which take a pointer to anobject as a parameter;

FIG. 40 is a flow chart showing an example embodiment of steps performedduring general function jacketing;

FIG. 41 is a flow chart showing steps to determine and use translationunits when performing a binary translation;

FIG. 41A is a flow chart showing steps to form translation units of anon-native binary image;

FIG. 42 is a flow chart showing steps of flow path determination;

FIG. 42A is a flow chart showing steps to determine transfer of controltarget locations for an indirect transfer instruction;

FIG. 43 is a block diagram showing two types of entries included in theprofile statistics;

FIG. 44 is a flow chart showing steps for determining regions;

FIG. 45 is a block diagram of a list of code cells;

FIG. 46 is a diagram which shows the relationship between FIGS. 47 and48;

FIGS. 47 and 48 are block diagrams which illustrate an arrangement oflocal data flow analysis information;

FIG. 49 is a block diagram of an opcode table;

FIG. 50 is a block diagram of a data flow analysis arrangementillustrating the use of read-modify and modify-write fields of the basicblock value (BBV) data structure of FIG. 47;

FIG. 51 is a block diagram which depicts the BBSC summary informationfield of FIG. 48;

FIG. 52 is a block diagram of an arrangement comprising global data flowanalysis information;

FIG. 53 is a more detailed block diagram of the global data flowconnections of FIG. 52;

FIG. 54 is a block diagram of the control flow edge (CFE) datastructure;

FIG. 55 is a flowchart that sets forth steps of performing a global dataflow analysis;

FIGS. 56A and 56B are flowcharts that set forth method steps fordetermining merge points during global data flow analysis;

FIG. 57 is a block diagram of a global data flow analysis arrangementillustrating a merge point.

FIGS. 58A-58D are block diagrams depicting different variations of thebinary image transformer;

FIG. 59 is a flow chart of steps of translating the binary image;

FIG. 60 is a flow chart of the step for one method for selecting thetranslation unit to be processed;

FIG. 60A is a representation of a call graph used in the method steps ofFIG. 60;

FIG. 61 is a flow chart depicting an alternative method for selecting atranslation unit to be processed;

FIG. 62A is a flow chart listing steps for forming an initialintermediate representation (IR) of a binary image;

FIG. 62B is a block diagram of a data structure illustrating atransformation of a source instruction to an IR with memory operandsremoved;

FIG. 62C is a block diagram of a data structure used to indicate whetheran IR instruction corresponds to a machine instruction which cangenerate an exception;

FIG. 63 is a flow chart showing steps for translating and optimizing aninitial IR to produce the final IR for a given translation unit;

FIG. 64 is a flow chart showing steps for performing condition codeprocessing;

FIG. 65A is a block diagram of a bit mask associated with an IRinstruction code cell used to represent condition codes that can beaffected by the corresponding IR instruction code cell;

FIG. 65B is a block diagram which depicts an example transformation fromsource instructions comprising the first binary image as affected bycondition code processing;

FIG. 66 is a flow chart depicting steps for register processing;

FIG. 67A is a block diagram which depicts a 32 bit register in anarchitecture which has partial register operands;

FIG. 67B is a block diagram which depicts a transformation of an initialIR as a result of register processing;

FIG. 68A is a block diagram which depicts a code pattern which isdetected by early floating point optimization processing;

FIG. 68B is a block diagram which is a table indicating a replacementinstruction for a specific code pattern detected in early floating pointoptimization processing;

FIG. 69 is a flow chart depicting steps for local basic block and globalroutine optimization processing;

FIG. 70 is a flow chart depicting steps of code selection and operandprocessing which place the IR in final form;

FIG. 70A is a flow chart depicting steps of intra image call processing;

FIG. 71A is a block diagram depicting a translated image comprisingtables used in exception handling;

FIG. 71B is a block diagram depicting a table entry in a translatorexception table; and

FIG. 71C is a block diagram depicting run time transfer of control whena translated image is executed and an exception occurs.

DESCRIPTION OF THE PREFERRED EMBODIMENTS

COMPUTER SYSTEM

Referring now to FIG. 1, a computer system 10, is shown to include aprocessor module 12 which has a high performance processor 12 a. Thecomputer system 10 further includes, in addition to the processor module12, a main memory 14, an disk adaptor 15 and an I/O user interface 18,as well as a monitor 19 all coupled by a system bus 20, as shown. Herethe processor 12 a is a high performance microprocessor such as anAlpha® microprocessor manufactured by Digital Equipment Corporation,assignee of the present invention, or other high performance processor.

The main memory 14 is comprised of dynamic random access memory and isused to store instructions and data for use by the microprocessor 12 aon the processor module 12. The disk adaptor 15 is used to couple thesystem bus 20 to a disk bus which itself is coupled to disk storagedevice 17.

The disk storage device 17 is here illustratively partitioned into aplurality of segments or blocks of data which are here represented forconvenience as being self-contained and contiguous, but which may bescattered across the disk 17 and be non-contiguous. The disk 17 includesa first storage segment 17 a storing an operating system for thecomputer system 10 as well as an application program stored in segment17 b.

The application program stored in segment 17 b is a non-nativeexecutable image. That is, the application program is comprised ofinstructions from a different instruction set than that used in thecomputer system 10 (i.e. a different computer architecture). Also theapplication program could have been written for a different operatingsystem than that stored in 17 a. Since the instructions provided in theprogram stored in segment 17 b are different from the instruction setexecuted on the microprocessor 12 a the program in segment 17 b can notbe directly executed on the system 10.

The disk also includes a storage segment 17 c which here represents annative executable image of the application program stored in segment 17b. This native image is generated in the computer system via a binaryimage conversion system (16, FIG. 2) which is here stored with theoperating system in the segment 17 a as will be described. The imagestored in segment 17 c corresponds to instructions which can be executedon the microprocessor 12 a and thus conforms to the architecture of thecomputer system 10.

Also stored in a segment 17 d are profile statistics which are collectedduring execution of a portion of the non-native application programstored in 17 b. The profile statistics are provided by execution of arun-time routine which converts non-native instructions into nativeinstructions. These profile statistics are used in a background processto convert portions of the non-native image into a native imagecorresponding to the operation and function of those portions of thenon-native application program. In addition, data which are used for theparticular application program are also stored on the disk in segment 17e.

The computer system 10 further includes an I/O user interface 18 whichis here an interface used to couple a mouse 19 a, for example, to thesystem bus 20 as well as a monitor 19.

The computer system 10 operates in a generally conventional manner. Thatis, at “power on”, selected portions (not numbered) of the operatingsystem stored in segment 17 a are loaded into main memory 14 and occupya particular address space in main memory 14, such as, address space 14a. As a user of the computer system 10 executes application programs onthe system 10, the application programs are run under the control of theoperating system.

A typical operating system represented by that stored in 17 a is theso-called Windows NT® operating system of Microsoft Corporation Redmond,Wash. In Windows NT® or other window type operating systems, displayableimages called “icons” are presented to a user on the monitor 19. Theseicons represent an executable command to initiate execution of aprogram. When pointed to by a cursor controlled by a mouse, for example,and clicked on this user action activates the command and causes therepresented computer program to execute.

Here, however, the application program stored in segment 17 b is writtenin a non native instruction set. That is, the instruction set of theapplication program is not the same as the instruction set of thecomputer system 10. Thus, the executable image of the applicationprogram stored in segment 17 b is comprised of non-native instructionswhich can not be directly executed on the computer system 10.Nevertheless, the non-native application has a corresponding icon (notshown) which is represented in the window provided by the operatingsystem.

Each non-native application image has a unique identification name (ID)or image key. The identification name or image key is included in thenon-native image file and is a unique identifier for the non-nativeapplication image. During installation of the file containing the image,typically a server process portion of the operating system determinesthe unique ID or key to the non-native application image. The ID numberis generally assigned by concatenating together unique information ofthe file. Examples of the types of information include, the time stampof the file, the file name, the file size and the date that the file wasoriginally produced. Thus, the same non-native image if loaded amultiplicity of times on the computer system will have the same I.D.number. The statistics as well as the translated code associated witheach one of the non-native images will be the union of all priorexecutions of the non-native images for each instance of the non-nativeapplication. Other arrangements are of course possible.

When the user clicks on the icon for the program stored in 17 b, aportion of the operating system recognizes the ID of the executableimage represented by that icon as being comprised of instructions thatare non-native to the instruction set and architecture of computersystem 10. In general a software module called a loader in the operatingsystem will recognize that the identification name (ID) of the filerepresented by the selected icon as being non-native to thearchitecture. Thus, the operating system initiates the execution of aninstruction conversion program 16 or feeds the file instruction by aninstruction to an instruction pre-processor. Alternatively, a loader canbe provided which handles the non-native image by examining the image todetermine all files, libraries and resources needed by the image. Theloader will thus prepare the non-native image for execution. Part of thepreparation is the initiation of the instruction conversion program 16or alternatively instruction pre-processor, as will now be described.

BINARY IMAGE CONVERSION SYSTEM

Referring now to FIG. 2, the binary image conversion system 16 is shownto include a run-time system 32 which is responsive to instructionsprovided from the disk segment 17 b. As mentioned, the run-time system32 can be implemented as software to emulate the non-native architectureor as a hardware preprocessor to convert the non-native instructionsinto native instructions. When implemented as software, the run timesystem 32 consumes more disk space on disk 17 and occupies more mainmemory storage in main memory 14. Whereas, when implemented in hardware,the run time system 32 requires more chip space in the high performancemicroprocessor 12 a. Here the run-time system will be described as asoftware implementation which operates in an execution address space 20of the computer system 10.

As mentioned above, disk segment 17 b stores instructions of anapplication program complied and/or written for an instruction set whichis different from the instruction set of system 10. The run-time system32 receives portions of a non-native executable image from segment 17 bcomprised of the non-native instructions. The run-time system 32provides a native instruction or a native instruction routine comprisedof a plurality of instructions which are executed by the computer system10 to provide the same functionality as the non-native image. That is,the functionality called for in the instruction in the executable imageof the non-native instruction set is equivalently provided by theroutines determined by the run-time system 32. The run-time systemexecutes the equivalent routines on the computer system 10. Thisprovides the equivalent function to provide the same result in computersystem 10 which implements the new architecture as would occur in a newor old computer system (not shown) implementing the non-nativearchitecture.

In a preferred embodiment of the run time system 32, the run-time system32 examines and tests the code from the segment 17 b to determine whatresources are used by the instruction and the function of theinstruction. The run-time system 32 provides the equivalent instructionscorresponding to the architecture of the computer system 10.

As the equivalent instructions are determined they are executed in thesystem 10 and profile data or statistics, as will be described, arecollected in response to their execution. The profile statisticsdescribe various execution characteristics of the instruction sequence.These profile data are fed to a server process 36 via a datapath 32 b.

Prior to performing a conversion by the run time system 32, the run-timesystem 32 interrogates the server process 36 via a path 32 a todetermine from the server process whether there is a native imagecorresponding to the routine of the application program stored insegment 17 b whose execution has just been requested by a user. If anative image does not exist (as would occur the first time thenon-native image is executed), the run-time system initiates aninterpretation process. If there is code in existence for the particularinstruction reached in the application program, due to a prior executionin the run-time system and subsequent conversion by a background system,the run-time system 32 will request and execute the native code.

As mentioned, in general, the first time the application program 17 b isexecuted by a user there will be no native image code in existence. Asthe program executes, however, native code will be generated by thebackground process in a manner to be described, and over time assubstantial portions of the non-native image are executed, convertibleportions of the non-native image will be converted by the backgroundprocess into native image code. As native image code is generated, it isalso stored in segment 17 c in a manner that is transparent to the user.

In addition the native image file 17 c contains an address correlationtable which is used to track the segments of native code correspondingto segments of non-native code. This table is used at run time of theprogram in segment 17 b to determine whether and which non-nativesegments have equivalent translated native segments.

Translation into the native image is provided via a background system 34which operates in one embodiment after the interpreter has finishedexecution of the instructions to provide translated code dependant uponthe execution characteristics of the run-time converted instructions.Alternatively, the background system operates while there is a pause inCPU utilization by the run-time system 32. Alternatively, the backgroundsystem can make translated code available to the run-time system 32during execution to permit substitution of translated code for asubsequent occurrence of the non-native image during the currentexecution of the application program. Further still, the run-time systemcan be implemented as a preprocessor which provides the profilestatistics for use by the background process. The background process canbe implemented in hardware or software or a combination of both.

The background system 34 receives the profile data generated by therun-time system 32. In accordance with the characteristics of theprofile data, the background system 34 forms a native image of at leastportions of the instructions of the non-native image stored in segment17 b of disk 17. A preferred arrangement is to have the backgroundsystem implemented as a binary translator to produce translated code.The native image portions are stored in logical disk drive 17′ for useif needed in subsequent executions of the application program fromsegment 17 b. Here it should be understood that the logical disk drive17′ is a logical partition of the disk drive 17 and is here referred toas being a logical disk drive, because in general, it is transparent tothe user, but it physically represents space storage such as segment 17c on the actual disk drive 17. Alternatively, the logical disk drive 17could be a separate disk drive.

The run-time system 32 and the background system are each under thecontrol of the server process 36. The server process 36 is presentthroughout the operation of the computer system 10. The server process36 is a software service process which, amongst other things, is used toschedule various transactions within and between the run-time 32 andbackground systems 34.

After generation of native image code such as by the binary translator,the image translated code is stored on logical disk drive 17′ in logicalsegment 17 c′ with the profile statistics being stored in logicalsegment 17 d′. These locations correspond to segments 17 c and 17 d inFIG. 2.

Each time there is a new execution of the application program stored insegment 17 b, the run-time system will send a request to the serverprocess 36 for native code corresponding to the non-native codecurrently in the run-time system 32. The translated code is code whichwas generated by a previous execution of the background system 34 inaccordance with the profile statistics collected by execution of theroutines furnished by the run-time system 32. The server process 36supplies corresponding translated code (if any) to the run-time system32. If there is translated code, the run-time system 32 will have thetranslated code execute in place of interpreting the code. Otherwise ifthere is no translated code, the run-time system 32 will interpret,translate, or otherwise converted the relevant portions of thenon-native code currently executed in the computer system 10.

As more code of the program stored in segment 17 b is executed, moresections of the program are interpreted producing as a result of theexecution, profile statistics which are fed to the server process 36.

The server process 36 controls inter alia the storage of the profilestatistics. That is, the server process 36 will merge new (raw)statistics with previously stored merged statistics to provide a newmerged profile. The server process will compare the new merged profilewith the stored merger profile and will initiate a translation processin the background system 34 when there is a difference between the twostatistics. The degree of difference needed to initiate execution isselectable. Such a difference indicates that heretofore never executedcode was interpreted and executed in the run-time system. This processwill be ongoing until all portions of the non-native image have beenencountered by the user and all of the portions which can be translatedby the background system 34 have been translated.

The server process also determines the unique key or I.D. number touniquely identify the non-native image stored in segment 17 b. Asmentioned above, the attributes of the image comprising the I.D. includethe file size, the date of creation of the image, the time stamp and soforth. This key is also used to identify the profile statistics with thenon-native program.

The background system 34 will, in general, translate nearly allinstructions provided from the non-native applications stored in 17 b.Certain types of instructions are preferably not translated. In generalthose instructions which are not translated are ones in which theexecution of the instruction is not predictable. For example,instructions which are self modifying (i.e. are not in read onlysections, that is, are on a writtable page) will not be translated. Forthese instructions the run-time system will execute them via theinterpretation routines. Further, instructions for which in thenon-native architecture there is no easily produced analog in the nativearchitecture will not be translated. For example, in the X86architecture of Intel, floating point instructions use a floating pointcontrol register to determine inter. alia. rounding modes etc. Althoughfor many executions of the instructions the contents of the register maybe in a normal state, this can not be guaranteed. Rather than have thetranslator determine the state it is more economical to handle theseinstructions in the interpreter.

Since execution or profile statistics in part determines what code istranslated by the background translator non-instruction code is notmistaken for instructions by the translator. Therefore, the translatedcode can be optimized without fear of optimizing non-instructions.

Referring now to FIG. 3, the run-time system 32 is shown to include anexecution address space containing run-time system 32 which includes arun-time interpreter 44, a non-native loader 42 which is fed the IDcorresponding to the non-native application image provided from segment17 b of the disk 17, a native image loader 43, native operating systemdll's (dynamic link libraries) 45 and a return address stack managementarrangement 20 (FIG. 22). The non-native loader 42 is similar to thenative image loader 43 except it is capable of handling non-nativeimages and interrogates the server process to determine whether there isany native code corresponding to the non-native code awaiting execution.The non-native loader 42 receives instructions corresponding to anon-native image of the application segment 46 a and a native image ofthe application 46 b corresponding to translated instructions providedfrom the background translator 34, and segment 46 c corresponding todata. The non-native loader 42 is used to initially load the non-nativefile. The native loader 43 is used to initially load the native file ifany.

Referring now also to FIG. 3A, at the initiation of an execution of theprogram stored in segment 17 b, (via selection of the appropriate icon)(step 50 a) the native loader 43 determines whether an architecturenumber associated with the non-native image is a native or a non-nativeimage. If the image is a native image execution continues as normal. Ifhowever the image is a non-native image, the native loader 43 calls thenon-native loader 42 at step 50 b. The non-native loader 42 loads thenon-native image at step 50 c and also recognizes that this architecturenumber associated with the program represents an application programwritten for a non-native instruction set. The non-native loader startsthe binary image conversion system 16. The non-native loader 42initially queries the server 36 at step 50 d to respond with native codeto accelerate execution of the image represented by the code stored in17 b. It should be appreciated that the function of the native loader 43and the non-native loader 42 can be combined into a single loader.

If this is the first time running the application, the server 36responds at step 50 e by indicating that there is no correspondingnative image to execute in place of the non-native image. Therefore, thenon-native loader 42 instructs the interpreter 44 to begin aninterpretation at step 50 f of the instructions from the non-nativeimage. The interpreter 44, for each instruction, determines the lengthor number of bytes comprising the instruction, identifies the opcodeportion of the instruction, and determines the resources needed by theinstruction. The interpreter maps the non-native instruction to a nativeinstruction or a native sequence of instructions based upon inter aliathe opcode. These instructions are executed by the computer system 10 inthe address space 20 (FIG. 3). The run-time interpreter 44 collects dataresulting from the execution of the instructions as will be described inconjunction with FIG. 6. These “profile statistics” are stored by theserver 36 on the logical disk drive 17′.

The run-time interpreter 44 examines and analyzes the instructions todetermine the proper native instruction sequence to replace for thenon-native instructions provided from the executable image 46 a. Thesenative instructions as they are executed continue to generate profilestatistics which are collected and stored in logical disk drive storage17 c′. This process continues until execution of the program 17 b isterminated by the user.

After termination of the execution of the non-native program, abackground process 34 is initiated (not shown). Alternatively, thebackground process 34 could be initiated to steal execution cycles fromthe run-time process 32 or alternatively could be used to substituteinto the run-time process translated native image code for routineswhich are subsequently called during execution of the program 17 b, asexplained above. The exact sequence of which the background processor isused in conjunction with the run-time processor is an implementationdetail.

For subsequent executions of the program the interpreter 44 will onlyprovide interpreter code if the server process 36 does not return anative image equivalent of the sequence which is provided from thebackground process 34 as will be described.

Thus, if at step 50 e the server responds with native code, the nativeimage loader 42 at step 50 g loads the native code. After the nativeimage code is loaded, the non-native image loader 42 is called at step50 h to fix up the image. In general the non-native image will provideaddress tables corresponding to inter alia variables in the non-nativeimage which are needed in the execution of the native image. That is, atstep 50 h the native and non-native images are stitched together toenable the native image to use information in the non-native image. Atstep 50 i the native code is executed. In general, the native code thatis executed corresponds to one or more basic blocks or routines ofinstruction which terminate by a return statement. After execution, adetermination is made based upon characteristics of the returninstruction execution and by use of a shadow stack as will be described,whether native image code can continue to be executed. If not thencontrol is transferred to the interpreter. The interpreter continues tointerpret and execute until it determines as at step 50 k that it canresume using native code.

As also shown in FIG. 3, a jacketing routine 48 is used to jacketfunctions leaving the execution address space 20 to the native executionspace of the computer process of computer system 10 as well as thosearising from the native execution space of the computer processor 10into the execution address space 20 as will be further described inconjunction with FIGS. 27-40.

Referring now to FIG. 4, a preferred embodiment of the background system34 is shown under the control of the server 36 (FIG.1). The server 36determines, responsive to the profile statistics data provided from theserver 36, via logical disk drive 17′, whether to initiate a translationprocess in the background. Preferably, the background system 34translates only portions of the non-native instructions of theapplication program which were actually executed (via the interpreter32) in responsive to a session invoking the program.

The non-native image code is examined at 52 in the server and if thecode is the type that should be translated, it is fed to the translator54. In a preferred environment, the translated code 54 is also fed to anoptimizer 58, and again, if the type of code is of a type which can beoptimized, it is fed through to the optimizer 58 or else, the processexits or terminates to await the submission of new code from executedportions of the non-native image stored at 17 b. Other, techniques forperforming translation and translation/optimization will be described.After the translator process 54 and/or the optimization processor 58,either translated code is stored in segment 17 b′ or optimizedtranslated code is stored in segment 17 b′.

PROFILE FILE DATA STRUCTURE

Referring now to FIG. 5, a profile file data structure 60 used to storeinformation gathered at execution time by instructions in theinterpreter 34 is shown. The data structure 60 has records which containinformation about the execution of a non-native architecture programwhen the program executes control transfer instructions. The profilerecord can include other information. That is, the profile recordscontain information about a target address encountered in the non-nativeimage.

The data structure 60 is shown to include two principal sections. Thefirst section is a profile header section 62 which comprises an imagekey field 62 a. The image key field 62 a is used to store informationregarding the ID or identification of the profile record. Theinformation in this field 62 a is used to associate the profilestatistics with a corresponding non-native image and its associatedtranslated code, if any. Thus, the image key field 62 a corresponds tothe image ID or key field as mentioned above. The profile header 62 alsoincludes a version field 62 b comprised of a major version field 62 b′and a minor version field 62 b″. The major version field 62 b′ and minorversion field 62 b″ are each here 16 bit or 2 bytes in length and theirunion provides a resulting 32 bit version field 62 b. The version fieldsare used to keep track of which version of the interpreter was used togenerate the profile statistics in the table and the profile fileformat.

The profile file 60 also includes a plurality of raw profile records,here 64 _(a)-64 _(n). Each of the profile records 64 a-64 _(n) maintainsinformation about run-time execution of control transfer instructions inthe non-native image. Each of these records are variable length recordsas is each of the unique profile files 60. Thus, for each controltransfer encountered during execution of the non-native image in theinterpreter 34 a raw profile record is produced. The interpreter 34 willplace into the raw profile record information regarding the execution ofthe control transfer instruction. The information which is included inthe raw profile record is as described below. Suffice it here to say,however, that the raw profile records are used by the server process toprovide a profile record which is then used during translation of theassociated routines in the background system.

Referring now to FIG. 6, an exemplary one of the raw profile recordshere 64 _(n) is shown. The raw profile record 64 _(n) includes a profilerecord structure 66 including an address field 66 a, a flag field 66 band a count field which tracks the number of indirect targets of controltransfer 66 c. The address field 66 a contains the actual target addressin the non-native image, as determined by the interpreter 44. Thisaddress is the actual target address of the instruction that caused acontrol transfer during execution of the non-native image. The addressfield 66 a is generally the address length of the non-nativearchitecture or here 32 bits or 4 bytes long. The flags field 66 bcontains the states of the flags at the target address. The flags field66 b is here 2 bytes or 16 bits long. The n_direct field 66 c is acounter field which keeps track of the number of indirect target orcomputed target addresses contained in the remainder of the profilerecord 64 _(n) as will be described below.

There are additional optional fields 70 which comprise the record. Onefield is a count field 70 a which corresponds to either the number oftimes a control transfer occurred to the address contained in field 66 aor a count branch taken field counter which keeps track of the number oftimes a branch was taken by the instruction corresponding to the addresscontained in field 66 a. Fields 70 b _(o)-70 b _(n) correspond toaddresses which are the targets of the control transfer and arecumulatively maintained in the profile record structure.

The optional fields 70 are used to keep track or maintain a count of thetargets of the control transfer instruction in the image. The countfield 70 a is either a control transfer field count of the number oftimes control was transferred to the target address or a branch takenfield corresponding to the count of the number of times a conditionalcontrol transfer of a branch instruction was taken. The type of field 70a is determined by the flags field 66 b being “ANDED” or masked with avalue which tests the state of the associated flag. This test determineswhether the target address was a result of a control transferinstruction or a branch instruction. This optional field is also a longword.

The target of control transfer fields 70 b ₁-70 b _(n) are the targetaddresses of the control transfer which occurred at the control transferinstruction. These fields keep track of the addresses for indirecttransfers, that is, transfers to a run-time computed target address.

The profile statistics are managed by the server process 36. The profilestatistics are collected by the interpreter 44 during the course ofexecution of the emulated code. For each execution the server 36searches for a profile record corresponding the target address. Theserver 36 merges the new run-time statistics with the existingstatistics to produce a new profile file.

The server 36 makes use of a software cache and hash table (not shown)to keep track of the profile records. For an address which need to belooked up the address is looked up in the cache in 4 different locationsthat is by using a four way associative cache (not shown). If theaddress is not there it is looked up in a conventional hash table. Theinformation in the hash table is the count values for the fields.

RUN-TIME INTERPRETER

Details of an interpreter used to convert non-native instructions tonative instructions and provide profile or run-time statistics will nowbe described. In particular the interpreter 44 interprets instructionsof the so-called X86 architecture by Intel Corporation San Francisco,Calif.) into ALPHA instructions by Digital Equipment Corp. will bedescribed.

Referring now to FIG. 7, an X86 instruction 100 is shown to include asmany as six different fields. These fields are an opcode 100 a, an rmbyte 100 b, a scaled index and base (sib) byte 100 c, a displacement 100d, any immediate data 100 e, and any one of six types of prefixes 100 f.

The opcode 100 a defines the task or operation which will be executed bythe instruction 100. The rm byte 100 b is an effective addressspecification and is used in conjunction with the opcode 100 a tospecify a general operand as a memory or register location and, in somecases, also participates in defining the operation. The sib byte 100 cis used in conjunction with the rm byte 100 b to provide additionalflexibility in addressing memory locations. The displacement field 100 dprovides a displacement from the base register or from virtual zero of asegment. The immediate data field 100 e provides immediate data to theopcode 100 a.

The prefixes 100 f are located before the opcode 100 a in theinstruction 100. Possible prefixes 100 f are a segment override whichimplements a second (or multiple) addressing space, a repeat specifiervalue to repeat a specific instruction n times, a lock assertion forsynchronization in multiple CPU environments, an address size prefixwhich selects between 16 and 32 bit addressing, an operand size prefixwhich selects between 16 and 32 bit operands, and an opcode prefix whichselects an alternative opcode set.

From the opcode 100 a it can be determined whether an rm byte 100 b, anunconditional displacement, or the immediate data field is provided inthe instruction 100. It can be determined from the rm byte 100 b whethera sib byte 100 c and/or a conditional displacement field 100 d isincluded in the instruction 100. As all fields are not required by eachIntel instruction 100, Intel instructions are not of a fixed length, butrather are of varying lengths.

The run-time interpreter 44 (FIG. 3) is, in the preferred embodiment,implemented on a computer system 10 (FIG. 1) which conforms to the Alphaarchitecture. An Alpha architecture computer system operates using theAlpha instruction set which is comprised of fixed length instructions.The run-time interpreter 44 operates on a single Intel instruction at atime. For each Intel instruction a single Alpha instruction or multipleAlpha instructions forming a corresponding Alpha routine, is providedwhich is an operational equivalent to the Intel instruction.

To transparently emulate the execution of an Intel or other non-nativeinstruction 100 the run-time interpreter 44 should be capable ofemulating the operation of the Intel or non-native memory, registers,condition codes and a program counter which, on a 32 bit Intel machineis referred to as an extended instruction pointer, EIP. In this way, aresult of the execution of the instruction 100 is recorded accurately.

The run-time interpreter 44 uses the same memory space for data whileexecuting Alpha routines corresponding to Intel instructions as is usedwhen executing native Alpha instructions. This is possible because thestrict standards to which Win32 software applications adhere allow fordifferences in calling conventions but not in the representation of thedata. The maintenance of the Intel registers, condition codes and EIPare discussed below.

Referring now to FIG. 8, a table 101 depicting Intel or non-nativevalues assigned to the registers of computer system 10 is shown toinclude eight registers which are assigned to emulate the operation ofthe eight Intel integer registers, EAX 104 a, EBX 104 b, ECX 104 c, EDX104 d, EDI 104 e, ESI 104 f, EBP 104 g, and ESP 104 h. A singleregister, CONTEXT 105, is assigned to serve as a pointer to the emulatorstate context maintained in memory which is used to manage each threadexecuting in a multitasking environment. An additional register, FSP106, stores a floating point stack pointer for addressing an eight entrystack of floating operands.

Three registers, CCR 107 a, CCS 107 b, and CCD 107 c are assigned tostore information which allow condition code bits to be maintained in anunevaluated state by the on-line interpreter 44. The SHADOW 108 registerprovides a pointer to the shadow stack (as will be described) whichmaintains activation records for translated code. The SEGOFF 109register maintains an offset from address zero in the nativearchitecture memory permitting the native architecture to emulatemultiple addressing spaces which are possible in the Intel architectureand other non-native architectures. Four additional registers T0 110 a,T1 110 b, T2 110 c and T3 110 d are assigned as temporary registers.

The frame 112 register identifies the activation record at the mostrecent activation of the run-time interpreter 44. The Emulator's ReturnAddress, ERA 114, register stores the return address when the run-timeinterpreter 44 calls a private sub-routine. The Effective Address, EA116, register stores the result of evaluating an RM byte 100 b and tospecify a memory address to a memory access routine.

Seven of the remaining registers, NXTEIP 118 a, NXTQ_LO 118 b, NXTQ_HI118 c, NXTJMP 118 d, Q0 118 e, Q1 118 f and QUAD 120 retain values whichare used by the interpreter 44 to identify a complete Intel instruction100 from the instruction stream and to provide pipelining capabilities.

To identify an Intel instruction 100, the run-time interpreter 44assembles an eight byte (64 bit) snapshot of the instruction streambeginning at the start of the current Intel instruction number. Thisquadword is retained in QUAD 120.

To assemble QUAD 120, the run-time interpreter 44 captures two quadwordsof information from the instruction stream. The run-time interpreter 44uses the address in the instruction stream identified by the nextextended instruction pointer, NXTEIP 118 a, as the starting address forthe first quadword. NXTEIP 118 a identifies a random byte in theinstruction stream at which the next instruction to be executed begins.Here, computer system 10 (FIG. 1) requires a quadword aligned addressfor this initial capture. Accordingly, if NXTEIP 118 a is not a quadwordaligned address, the three low order bits are first zeroed thus forcingthe capture to occur beginning at a quadword boundary. The quadwordcaptured beginning at this quadword aligned address is stored inregister Q0 118 e. By executing the capture in this manner, the quadwordstored in register Q0 118 e will at least provide the low byte of thenext instruction.

The second quadword capture occurs at an address identified by NXTEIP118 a incremented by seven bytes. Here again, computer system 10requires a quadword aligned address for this second capture. If theaddress identified by NXTEIP 118 a incremented by seven bytes is notquadword aligned, the run-time interpreter 44 forces the three low orderbits to zero thus forcing the address to be quadword aligned. From thisquadword aligned address, the capture is performed and the quadword isstored in register Q1 118 f. Here, the quadword stored in register Q1118 f contains at least the high order byte of the quadword beginning atthe next instruction as identified by NXTEIP 118 a.

To extract the low order bytes of the quadword beginning at NXTEIP 118a, the run-time interpreter 44 executes an instruction which, using thethree low bits of NXTEIP 118 a, determines a byte in register Q0 118 ewhich is identified by NXTEIP 118 a, whether or not this byte isquadword aligned. The data in register Q0 118 e is copied to registerNXTQ_LO 118 b and shifted right to locate the byte identified by NXTEIP118 a in the low order byte register NXTQ_LO 118 b. The high order bytesof NXTQ_LO 118 b which, after the shift, no longer contain validinformation are zeroed.

The three low bits of the address identified by NXTEIP 118 a incrementedby seven bytes is used to determine the high order byte of the quadwordbeginning at NXTEIP 118 a. Here, the data in register Q1 118 f is copiedto register NXTQ_HI 118 c shifted left to locate the byte identified byNXTEIP 118 a incremented by seven bytes in the high order byte ofregister NXTQ_HI 118 c. Here, the low order bytes of NXTQ_HI 118 c whichno longer contain valid information as a result of the shift are zeroed.The result of ORing the contents of registers NXTQ_LO 118 b and NXTQ_HI118 c is stored in QUAD 120.

Referring now to FIG. 9, the low bit of QUAD 120 is shown to be alignedwith an Extended Instruction Pointer, EIP 121. In an Intel machine, theEIP 121 identifies a location in the instruction stream whichcorresponds to the beginning of the current instruction. As eachinstruction in the instruction stream is executed, the EIP 121 isincremented in the instruction stream to point to the beginning of thenext instruction. QUAD 120, therefore, holds a quadword of informationbeginning at the byte identified by EIP 121.

To determine the operation of the Intel instruction 100 and acorresponding Alpha routine which performs the operational equivalent ofthe Intel instruction 100, the interpreter uses the informationcontained in QUAD 120. Typically, the first byte of an Intel instructionis the opcode 100 a as shown in FIG. 7A. The run-time interpreter 44extracts the first and second low bytes 120 a, 120 b of QUAD 1002 toprovide a two byte instruction fragment 122. From this two byteinstruction fragment 122, a corresponding Alpha routine and the lengthof the instruction 100 are determined.

Referring now to FIG. 10, an arrangement 130 to determine the length ofthe Intel instruction 100 and the corresponding Alpha routine whichimplements the operational equivalent of the Intel instruction 100, isshown. The arrangement 130 extracts the two low bytes 120 a, 120 b fromQUAD 120 to provide the two byte instruction fragment 122. This two byteinstruction fragment 122 is used as an index into a dispatch table 131which resides in system memory 14 (FIG. 1).

The dispatch table 131 includes 2¹⁶=64 K (65536), 32 bit entries ofwhich entry 131 i is representative. Each entry corresponds to eachinstruction in a set of instructions available in the Intel instructionset. The contents of these 32 bit entries 131 i include a field 131 acontaining an address at which the corresponding Alpha routine residesin system memory 14 as well as a field 131 b containing the length ofthe instruction.

The dispatch table 131 is generated by a tool which identifies eachinstruction in the Intel instruction set such that the two byteinstruction fragment 122 is sufficient information to identify theproper entry which corresponds to the current Intel instruction 100. Thetool also provides the complete length of the Intel instruction 100 andincludes this information in the dispatch table in the length field 131b along with the location of the Alpha routine which will provide thefunctional equivalent of the Intel instruction 100 in the address field131 a. The run-time interpreter 44 chooses among eight dispatch tablesbased upon the sequence of prefix elements 100 f preceding the actualopcode 100 a.

As discussed above in conjunction with FIG. 7, an Intel instruction 100may be comprised of multiple elements 100 a-100 f. Multiple dispatchtables are provided by run-time interpreter 44 to handle the differentvalues and combination of values which can be selected by the prefixelement 100 f. As discussed above, three possible prefixes 100 f areaddressing size (16 or 32 bits), operand size (16 or 32 bits) and twobyte opcode, which selects an alternative opcode set. Any one orcombination of these prefixes 100 f may be present in an Intelinstruction 100.

The addressing size prefix toggles between an addressing size for theIntel system which truncates address arithmetic to 16 bits or to 32bits. Typically, the address size is 32 bits. The operand size prefix issimilar wherein an operand expected by the system is 16 bits under a 16bit operand size or 32 bits when the operand size is set for 32 bits.Here again, the typical operand size is 32 bits. The final prefixtoggles between two alternative opcode sets. The first is a one byteopcode set and the second is a two byte opcode set. Here, a one byteopcode set is typically selected. A dispatch table similar to thedispatch table 131 in FIG. 10 is provided in system memory 14 for eachof the eight possible combinations of prefixes 100 f, the defaultdispatch table is dispatch table 131 having a 1 byte opcode with a 32bit addressing size and a 32 bit operand size.

In addition to an entry for each instruction, also included in dispatchtable 131 is an entry for each prefix 100 f and prefix 100 fcombination. The 32 bit entry 131 j, corresponding to a prefix 100 f,activates a different dispatch table in memory 14 in which thesubsequent opcode 100 a in the instruction stream and its correspondingtwo byte instruction fragment 122 may be used to index the proper 32 bitentry 131 i.

Referring now to FIG. 11, a process for activating an alternate dispatchtable 131′ is shown to include extracting a two byte instructionfragment 122 from QUAD 120. The two byte instruction fragment 122 isused as an index into the dispatch table 131.

Here, the two byte instruction fragment 122 identifies an entry in thedispatch table 131 j. The dispatch table entry 131 j includes a nativeroutine address 131 a in memory 14 and the length 131 b of the Intelinstruction 100 which here, is 001 or one byte. The first byte of thetwo byte instruction fragment 122 is a prefix 100 f to instruction 100which selects 16 bit addressing. Accordingly, the native routine 132identified by the native routine address 131 a, instructs the run-timeinterpreter 44 to activate the dispatch table 131′ which corresponds toan instruction set implementing 16 bit addressing.

The length 131 b of the Intel instruction 100 is provided to therun-time interpreter 44 which increments EIP 121 one byte in QUAD 120 toidentify the beginning of the next instruction. A new two byteinstruction fragment 122′ is extracted from QUAD beginning at the newlocation identified by EIP 121. This two byte instruction fragment 122′identifies an entry 131 i′ in dispatch table 131′. Again, the twoportions of the dispatch table entry 131 i′ identify the native routineaddress 131 a′ in memory 14 of the native routine 134 which is theoperational equivalent of the Intel instruction 100 and the length 131b′ of instruction 100.

The run-time interpreter 44 executes the native routine 134 whichprovides the operational equivalent of Intel instruction 100. Oncecomplete, the on-line interpreter activates the default dispatch table131 for 32 bit addressing and operands and one byte opcodes. While therun-time interpreter 44 is executing the native routine 134 for Intelinstruction 100, the process just described allows the run-timeinterpreter 44 to identify the beginning of the subsequent instructionby incrementing EIP 121. In addition, the entry in the active dispatchtable 131 which corresponds to the subsequent instruction is alsoidentified. From this entry 131 n, the address of the native routine 131na corresponding to the subsequent instruction as well as the length 131nb of the subsequent instruction are determined. This arrangement allowsthe on-line interpreter to operate in a pipelined fashion, executingmultiple instructions in parallel.

Referring now to FIG. 12, a 32 bit entry 131 i from dispatch table 131is shown to be divided into two sections, the first section 131 acorresponding to bits 3-31 of the 32 bit entry 1012 and the secondsection 131 b corresponding to bits 0-2 of the 32 bit entry. Bits 3-31,section 131 a are used to address the Alpha routines which execute theoperational equivalent of the Intel instruction 100 and bits 0-2 131 bsignify the length of the Intel instruction 100.

The dispatch table targets are aligned on quadword boundaries. That is,the Alpha instructions which the entries in the dispatch table 131 pointto and execute the operational equivalent of Intel instruction 100, arelocated in system memory 14 on quadword boundaries. In this way, bits0-2 of the address of the Alpha instructions are always zero. As aresult, bits 0-2 131 b′ may be used to convey additional informationabout the instruction as here, where these bits are used to signify thelength of the instruction. As the addresses of the Alpha routines arealways 000 in bits 0-2 field 131 b′, a full 32 bit address is recreatedby appending these zeros to bits 3-31 1012 a to provide a complete 32bit address.

As control is passed to the Alpha routine identified by the 32 bitaddress, bits 0-2 are used to increment EIP 121 so that EIP 121 ispointing to the beginning of the next instruction. Here, if the lengthof the Intel instruction 100 is from 1-6 bytes in length, QUAD 120contains sufficient information to form a second, two byte instructionfragment 122 which may be used to index the current dispatch table todetermine the corresponding Alpha routine for the next Intelinstruction. This arrangement allows the run-time interpreter 44 topipeline instructions and thus execute the application program morequickly and efficiently. While an Alpha routine is being accessedcorresponding to a current instruction, the run-time interpreter 44 isable to determine the address and length of the next Intel instruction100 in the instruction stream. A value of zero returned from bits 0-2field 131 b of the 32 bit entry 131 i for the length of the Intelinstruction 100 however, indicates that the instruction was longer than6 bytes and hence, pipelining is not possible for this Intel instructionand accordingly, the EIP 121 is not incremented. It is then theresponsibility of the Alpha routine to increment EIP 121 and to refillthe pipeline.

CONDITION CODE PROCESSING

Referring now to FIG. 13, general purpose registers 135 of an Intel X86machine are shown to include a single register, EFLAGS 135 a, in whichcondition codes are maintained. This register, EFLAGS 135 a, maintainsthe six condition code bits, the Carry bit 136 a (C), the Negative bit136 b (N), the Zero bit 136 c (Z), the Overflow bit 136 d (O), theParity bit 136 e (P), and the Low Nibble Carry bit 136 f (A). Each ofthese bits may be cleared or set as a result of the execution of anIntel instruction 100. To completely emulate the operation of the Intelapplication, the run-time interpreter 44 also maintains, in anunevaluated state, the current state of the condition codes resultingfrom the execution of an Alpha routine which corresponds to the Intelinstruction 100.

As is often the case in systems which maintain condition codes, asubsequent condition code modifying instruction may be executed, thusoverwriting the changes made to the condition code bits by a priorcondition code modifying instruction, before the state of the conditioncodes is required by a subsequent instruction. In addition, many of thecondition code modifying instructions effect only a partial set of thecondition code bits. Accordingly, a complete evaluation of the conditioncode bits after execution of every condition code modifying instructionwould be wasteful at CPU time. Nevertheless, the state of the conditioncode bits needs to be readily ascertainable throughout the execution ofthe X86 image should the current state of the condition codes berequired.

Referring now to FIG. 14, the run-time interpreter 44 is shown toinclude a set of data storage locations 138, a table of methods 139, andevaluation routines 140 which are used to emulate the X86 conditioncodes during execution of an X86 image in computer system 10.

The set of data storage locations 138 is shown to include threelocations 138 a, 138 b, 138 c which are updated upon execution of aninstruction which would have modified the condition codes in an X86system. The first location, data1 138 a, and the second location, data2138 b, store data used in the execution of the instruction, for example,an operand and a result of the instruction. This information is usedlater during execution of the application program should it becomenecessary to evaluate the condition codes.

The third location, pointer 138 c, contains a pointer to the table ofmethods 139 which is a dispatch table used to evaluate the conditioncodes should the system require the current value of the conditioncodes. The table of methods 1022 contains an entry for each of the eightpredicates available in X86 conditional branches (and equivalent SETccinstructions), an entry to obtain the nibble carry, A 136 f, bit and anentry to obtain a complete image at the EFLAGS 135 a register. The setof methods includes one for each of the six condition codes.

Each entry in the table of methods 139, identifies an evaluation routine140 which evaluates the condition described in the method table entry.Data1 138 a and data2 138 b are provided to the evaluation routines todetermine the state of the condition code bits should a subsequentinstruction require the current state of the condition codes.

When an Alpha routine is executed for an Intel instruction which wouldhave modified one or more of the condition codes, the run-timeinterpreter 44 stores zero to two pieces of information from theinstruction in the first two storage locations, data1 138 a and data2138 b. These pieces of information, possibly an operand and a result ofthe operation, are used by the evaluation routines to compute thecondition codes. In the third storage location, pointer 138 c, a pointeris placed which, in accordance with the type of instruction which wasexecuted, identifies the entry in the table of methods 139 which willidentify the evaluation routines 140 which are to be called if and whenthe condition codes are evaluated.

The table of methods 139 is specific to the type of instructionexecuted. That is, if the instruction modifies all of the conditioncodes, the table of methods includes an entry pointing to a routine foreach of the six condition codes. If the instruction modifies only the Cbit, the only entry in the table of methods 138 is a entry pointing toan evaluation routine which will evaluate the C bit. Other possibilitiesinclude instructions which modify all of the condition code bits exceptfor the C bit (ALL_BUT_C) instructions which modify only the Z bit(ONLY_Z) and instructions which modify only the C and O bits (C_AND_O).The table of methods 139 for instructions of these types would includeentries pointing to routines which correspond to all but the C bit, onlythe Z bit and only the C and O bits respectively.

Each entry in the table of methods 138 identifies a separate evaluationroutine 140 which computes that specific condition code predicate orimage of EFLAGS 135. Because these routines are only executed whennecessary, the condition codes are maintained in an unevaluated stateand accordingly, only minimally effect the execution speed of theapplication. Data1 138 a and data2 138 b are provided to the evaluationroutine 1024 to determine the effect the instruction had, or should havehad, on the condition codes. Later, when a subsequent instruction isencountered by the run-time interpreter 44 which requires the currentvalue of one or all of the condition code bits as input to theinstruction, for example, as a condition in a conditional instruction,the run-time interpreter 44 uses the information provided in the datastorage locations 138 a and 138 b, the table of methods 139 and theevaluation routines 140 to determine the current values of the conditioncode bits.

As discussed above, an Intel instruction can modify all condition codebits, or a subset of those bits. If the current instruction whichmodified the condition code bits modifies only the C bit and theprevious instruction modified all of the condition code bits it would bewasteful to gather the data necessary to evaluate all but the C bit andcopy it into the table of methods 139 which is provided for the currentC bit modifying instruction. As a result, the run-time interpreter 44maintains information to evaluate the previous state of the conditioncode bits based upon a previous condition code modifying instruction aswell as the current condition code modifying instruction.

Referring now to FIG. 15, the interpreter is shown to include two setsof data storage locations 138 and 138′, two corresponding tables ofmethods 139 and 139′ and corresponding evaluation routines 140 and 140′.A first condition code evaluation grouping 137 corresponds to a currentcondition code modifying instruction and a second condition codeevaluation grouping 137′ corresponds to a previously executed conditioncode modifying instruction. Further, a finite state machine (FSM) isprovided which determines how the previous and current states of thecondition codes are maintained. The states and transitions of the FSMare the five types of condition code updates: ALL_BUT_C, ONLY_C,C_AND_O, ONLY_Z and ALL. Each transition has associated with it one ofthree actions: replace, push or resolve.

Provided below is a table, TABLE 1, which describes the action taken tomaintain the condition code bits. The action is contingent upon whichcondition code bits the current instruction will modify as well as whichcondition code bits were modified by a previously executed conditioncode modifying instruction. In addition, the actions have been carefullyselected to provide an action for the transition which entails a minimalamount of work yet still provides the run-time interpreter 44 a completeup-to-date set of condition code bits at any time.

In a replace action, the contents of the current condition codeevaluation grouping are replaced by the values resulting from the nextinstruction. That is, the contents of the data storage locations 138,the corresponding table of methods 139 and the evaluation routines 140are replaced with values which will enable the run-time interpreter 44to evaluate the condition codes modified as a result of the nextinstruction. A replace action does not modify the contents of theprevious condition code evaluation grouping. A replace action isappropriate when the set of condition code bits modified by the nextcondition code modifying instruction includes at least all of thecondition code bits in the set of condition code bits modified by themost recent condition code modifying instruction.

A push action however, replaces the contents of the previous conditioncode evaluation grouping 137′ with the contents of the current conditioncode evaluation grouping 137. The current condition code evaluationgrouping 137 is used to provide the necessary information to evaluatethe condition code bits modified by the next instruction. A push actionis appropriate when the set of condition code bits modified by the nextcondition code modifying instruction does not include all of thecondition code bits in the set of condition code bits modified by themost recent condition code modifying instruction. In addition, a unionof the two condition code bit sets results in a complete set ofcondition code bits.

The final action is a resolve. The resolve is the most complicated ofall the actions. In a resolve, the state of the condition codes, asrepresented by the current and previous condition code evaluationgroupings 137 and 137′, is evaluated resulting in a complete set ofcondition code bits, or an ALL, in the current condition code evaluationgrouping 137. A push is then performed for the next instruction. Aresolve action is appropriate when more than two condition codeevaluation groupings would be necessary to maintain a complete set ofcondition code bits.

TABLE I Next CC Most Recent CC State State ALL_BUT_C ONLY_C C_AND_OONLY_Z ALL ALL_BUT_C replace push push replace push ONLY_C push replaceresolve resolve push C_AND_O push replace replace resolve push ONLY_Zresolve resolve resolve replace push ALL replace replace replace replacereplace

As mentioned above, the first condition code evaluation grouping 137maintains in an unevaluated state the state of the condition codescorresponding to the execution of a current instruction. The secondcondition code evaluation grouping 138 maintains in an unevaluated statethe state of the condition codes corresponding to the execution of aprevious instruction.

The first set of data storage locations 138 here, registers CCR 107 a,CCS 107 b and CCD 107 c retain three values. CCR 107 a and CCS 107 bcontain data used by the current, non-native instruction such as anoperand and a result of the instruction. CCD 107 c contains a pointer tothe dispatch table 139 provided to evaluate the state of the conditioncodes which are modified as a result of the execution of the currentinstruction. The second set of data storage locations 138′ retainsimilar values corresponding to a previous condition code modifyinginstruction.

Here, each condition code evaluation grouping 137, 137′ is shown toinclude a location in the respective table of methods 139, 139′ whichindicates the category of instruction which was executed. That is,whether the instruction modifies all of the condition code bits or asubset of the condition code bits. Using this value and the informationin the FSM of TABLE I, the run-time interpreter 44 maintains in anunevaluated state, the complete set of condition code bits.

To illustrate how this works, an example is provided in conjunction withFIG. 15, in which a current instruction modifies all of the conditioncode bits (ALL) and a next instruction modifies only the C bit (ONLY_C).In this simple example, the contents of the second condition codeevaluation grouping 137′, which provides the previous condition codestate, is immaterial as will be shown.

As the current instruction modifies all of the condition code bits, thecategory location 139 a of dispatch table 139 would indicate an ALLvalue. Accordingly, an entry for each of the six condition code bits isprovided in dispatch table 139 a to access evaluation routines 140 foreach condition code bit.

When the corresponding Alpha routine for the next instruction isexecuted, the category location 139 a of the current dispatch table isaccessed to determine the category of the previous instruction. Usingthe category information provided and the information contained in TABLE1 the run-time interpreter 44 manipulates the contents of each conditioncode evaluation grouping 137, 137′ accordingly.

Here, the category of the most recently executed instruction is ALLwhile the category of the next instruction is ONLY_C. As shown in TABLEI, when the most recent condition code state is an ALL and the nextinstruction is an ONLY_C, the action which is to be taken is a push.Here, a push is an appropriate action because the set of bits modifiedby the next condition code modifying instruction, {C}, does not includeall of the bits modified by the most recently executed condition codemodifying instruction, {C, N, O, P, A}. Moreover, a union at the twocondition code bit sets results in a complete set of condition codebits, {C, N, Z, O, P, A}.

The information retained in the current condition code evaluationgrouping 137 is pushed or copied into the storage locations for theprevious condition code evaluation grouping 137′. That is, the data inCCR 138 a and CCS 138 b are copied to pdatal 138 a′ and pdata2 138 b′respectively and CCD 138 c is copied to pptr 138 c′. The currentcondition code evaluation grouping 137 is then used to store the dataused to evaluate the C bit which is the only condition code bit modifiedby the next instruction. An example is provided below in conjunctionwith FIGS. 16 and 17 which describes a resolve action.

Referring now to FIG. 16, a set of condition code state diagrams 150includes a condition code state 152 diagram for a previously executedcondition code modifying instruction, a condition code state 154 diagramfor a most recently executed condition code modifying instruction and acondition code state 156 diagram for a next condition code modifyinginstruction. Here, the previous condition code state 152 is ALL_BUT_C inwhich all but the C bit is modified. The most recent condition codestate 154 is C_AND_O in which only the C and O bits are modified as aresult of the execution of the most recently executed condition codemodifying instruction. The next condition code state 156 is ONLY_C inwhich only the C bit is modified.

Referring back to TABLE 1, it may be seen that when the most recentstate is C_AND_O and the next state is ONLY_C the appropriate action tobe taken is a resolve action. It can be seen from FIG. H a replaceaction would not preserve the most recent state of the O bit as thecurrent condition code state would be overwritten by information onlycapable of determining the C bit. A push however would lose theinformation necessary to determine the most recent values of the N, Z, Pand A bits. As discussed above, more than two condition code evaluationgroupings would be required to fully preserve the current states of eachof the condition code bits. Accordingly, the information stored in thefirst and second condition code evaluation groupings 137, 137′ isresolved resulting in a complete set of condition code bits.

Referring now to FIG. 17, the most recent condition code state 154′diagram is shown to contain a complete set of condition code bits. As aresult of the resolve action, the most recent condition code state 154′is ALL and the next condition code state 156′ is an ONLY_C. Referringagain to TABLE 1, the appropriate action to be taken is a push when themost recent condition code state is ALL and the next condition codestate is ONLY_C. Accordingly, the run-time interpreter 44 can push thecondition code information resulting from execution of the nextinstruction without losing any condition code bit information.

Referring now to FIG. 18, the previous condition code state 152″ diagramis shown to indicate a complete set of condition code bits which waspushed from the most recent condition code state 154′ in FIG. 17. Themost recent condition code state 154″ diagram of FIG. 18 now indicatesexecution of a condition code modifying instruction which modified onlythe C bit. As may be seen, all information relating to the most currentstate of each of the condition code bits has been preserved.

MULTIPLE ADDRESS SPACES

Referring now to FIG. 19, an implementation of multiple address spaceson an Intel machine is shown to include segments CS 160, DS 162, and SS164 identifying address 0 166 of a first address space 168 and segmentFS 170 identifying address 0 172 of a second address space 174. Data X168 i is located within the first address space 168 and data Y 174 i islocated within the second address space 174.

It should be noted that the first address space 168 and the secondaddress space 174 exist independently from each other. Accordingly,there is no relationship between the location identified by segments CS160, DS 162, and SS 164 and segment FS 170. Nor is there anyrelationship between the address of the location of data X 168 i in thefirst address space 168 and address of the location of data Y 174 i inthe second address space 174.

Referring now to FIG. 20, emulation of multiple address spaces on anative architecture is shown to include segments CS 160′, DS 162′, andSS 164′ identifying address 0 166′ of a first address space 168′ andsegment FS 170′ identifying address 0 172′ of a second address space174′ where segment FS 170′ has an offset 175 from address 0 166′ of thefirst address space 168′. The value of the offset 175 is stored inSEGOFF 109 (FIG. 8).

CONTEXT DATA STRUCTURE

Referring now to FIG. 21, a context data structure 180 which resides inmemory is shown. The context data structure 180 is used by the on-lineinterpreter 44 to handle multitasking capabilities of the non-nativesoftware application. When, due to multitasking, an additional thread isexecuted during operation of the non-native software application, asnap-shot of the current state of the run-time interpreter 44 is savedin context data structure 180. The context data structure 180 is used bythe new thread to provide the run-time interpreter 44 executing in thenew thread the state of the run-time interpreter 44 executing in thethread which initialized the new thread.

Values which are saved in the context data structure 180 include thecurrent condition code state in field 181. Thus, this field includessubfields (not shown) to provide copies of the values stored inregisters CCR 138 a, CCS 138 b and CCD and 138 c. Values are provided infield 182 to store the previous state of the condition code bits. Thecontext data structure also includes copies of the integer registers EAX104 a, EBX 104 b, ECS 104 c, EDX 104 d EDI 104 e, ESI 104 f, EBP 104 gand ESP 104 h in field 183.

In field 183 values for the six segments (seldomly used in WIN32applications) are provided. The six segments, four of which are depictedin FIGS. 19 and 20 are cs, ds, es, fs, gs and ss. A copy of the floatingstack pointer 106 (FIG. 8) is also provided in field 185 in addition toa starting value for the floating stack pointer as well as the floatingstack entries.

Field 186 of the context data structure 180 provides pointers to each ofthe eight possible dispatch tables. Exemplary dispatch tables 131 and131′ are depicted in FIGS. 10 and 11. The context data structure 180also provides in field 187 the Extended Instruction Pointer, EIP 121.

A repeat specifier value, as designated by one of the possible prefixes100 f (FIG. 8), is provided in field 188. Values relating to theEmulator Return Address, ERA 114, register are stored in field 189. Infields 190 and 191 pointers used to maintain the profile table as wellas pointers to portable math routines are also provided respectively.Values of selected constants are also provided in the context datastructure 180 in field 192 while pointers to maintain a linked list ofcontext data structures is provided in field 193.

An additional aspect of a preferred embodiment includes structuring theorder of the software which implements the run-time interpreter 44 suchthat critical blocks of the software code exist in a single cache block.In this way, the run-time interpreter 44 is able to execute moreefficiently as the portions of the interpreter 44 which are executedmost often are resident in the cache.

NON-NATIVE RETURN ADDRESS STACK AND SHADOW STACK

Referring now to FIG. 22, a return address stack arrangement 210 isshown to include a non-native return address stack 211 and a shadowstack 212. The non-native return address stack 211 is an address stackwhich is produced as if the non-native image were executing in thenon-native environment. The non-native return address stack 211comprises a plurality of frames 219, each of said frames including acorresponding one of non-native return address fields 213 a-213 c, aswell as fields 215 a-215 c for local storage, as shown. The non-nativereturn address stored in locations 213 a-213 c corresponds to theroutine return address that is pushed onto the stack by the program whenit executes a call instruction. That is, the non-native program whenexecuting in a native environment would place on the stack 211 aparticular return address corresponding to the address space as if thenon-native program was executing in its native environment.

As also mentioned, the return stack arrangement 210 also includes ashadow stack 212. The shadow stack 212 likewise is comprised of aplurality of frames 214, each of said frames 214 comprising a headerfield 216 a-216 c and corresponding or associated local storage fields218 a-218 c.

The return address arrangement 210 also includes a pair of stackpointers, one for the non-native return stack 211 and one for the shadowstack 212. The non-native return address stack pointer 217 also referredto as SP points to the bottom or most recent entry in the non-nativereturn address stack. Here the non-native return address stack 211 hasan initial address A₀ of <7FFFFFFF>. The initial address of <7FFFFFFF>insures that as the stack pointer SP is decremented, the largest stackpointer value will not be sign extended by an LDL instruction as will bedescribed. Likewise, the shadow stack 212 has a stack pointer 221referred to as SSP and has an initial address A₀=<0000000077FFFFFFF>.

The header portion 216 a-216 c of the shadow frames 214 here comprisesfour sub-fields. The first sub-field 220 a also referred to as SP is thecontents of the non-native stack pointer 17 corresponding to the returnaddress in the non-native stack pointer for the particular shadow stackframe 214. Here the non-native stack pointer corresponds to the size ofthe emulated operating system. Thus, for a 32 bit operating system, thenon-native stack pointer 220 a would comprise four bytes.

The second entry 220 b in the header 216 a-216 c is the non-nativeinstruction pointer value 220 b. The non-native instruction pointer isthe address that is pushed onto the non-native return address stack 211.This address also comprises the same number of bytes as the number ofbytes supported in the operating system. Thus, again for a 32 bitoperating system, the number of bytes is 4.

The third entry 20 c in the header portion 216 a-216 c is a nativereturn address field 220 c. The native return address field 220 ccomprises the native return address which is placed on the shadow stackif a translated routine executes a call instruction. This corresponds tothe address of the native instruction which is to resume execution inthe translated routine after the called routine has completed.

The fourth entry in the header 216 a-216 c is the native dynamic link220 d. The native dynamic link field is a pointer to the previous shadowframe header 214. Thus, in FIG. 22, the value stored in the field“dylnk” corresponds to the location of the next shadow frame header 216b. This value is preferably included in the shadow stack 212 to allowthe shadow stack 212 to make provisions for a variable amount of localstorage in fields 218 a-218 c. In situations where the local storagefields are not provided or their size is fixed, it is not necessary tohave a dynamic link field.

The local storage fields 215 a-215 c in the non-native register stack211 comprises routine calls and routine arguments of the non-nativesystem and is provided to faithfully replicate that which would occur inthe non-native system were it being executed on its native architecture.The routine locals and routine arguments stored in the non-native returnstack are passed to translated routines via the translation processdescribed above and as will be further described in detail below. In theshadow stack 212, however, provision is also provided for local storagein fields 218 a-218 c. For example, often when a compiler is used tocompile a program, the actual instructions of the program use morelogical registers than physically exist in the machine on which theprogram is to be executed. Accordingly, the compiler often providestemporary storage for logical register manipulations and uses theprogram stack to store these registers.

NON-NATIVE RETURN STACK AND SHADOW STACK MANAGEMENT

The non-native return address stack 211 is managed exactly as dictatedby the non-native code being emulated in the interpreter 44. When theinterpreter 44 is executing the non-native or non-native code of aparticular thread, there is only one native frame on the shadow stack212 for the interpreter. This permits the interpreter to transferexecution into translated code in the event that there is correspondingtranslated code to be executed. The interpreter does not push framesonto the shadow stack 212. Further, when transferring into and out oftranslated routines, the interpreter does not push data onto the nativesystem stack. Rather, when transferring into and out of translatedroutines, shadow frames 214 are pushed onto the shadow stack 212 torecord the state associated with the translated routines.

The shadow stack 212 tends to be synchronous with the routine frames onthe non-native return stack. Although calling jackets (48FIG. 3) maycause another instance of the interpreter 44 to be produced if acallback is performed, and thus push another interpreter frame onto thenon-native return address stack 211, once the jacketed operation hasbeen completed this extra frame is removed from the non-native ornon-native stack 211.

With a translated routine, however, a shadow frame 214 is pushed ontothe shadow stack 212 each time a translated routine is called. Theshadow frame 214 includes the space necessary for the translatedroutine's locals such as the spilled registers mentioned above, and theshadow frame header.

Referring now to FIG. 23, an example of the operation of the shadowstack 212 is shown. The program 230 includes a routine A which has aplurality of instructions, one of which is a call to a routine B (callB) at 233. Routine B, likewise, has a plurality of instructions with thelast instruction being a return instruction RET. Program flow 230represents a program flow for the non-native program executing in itsnative environment. In routine A, when the Call B instruction 233 isexecuted, it causes the next instruction at address A_(N) to be pushedonto the non-native return address stack 211, as shown. The stackpointer for the non-native instruction stack 211 is incremented to thenext value, thus pointing to the entry for A_(N). Routine B is called byroutine A and executes its instructions causing at the last instruction(RET) a return which causes a pop from the non-native return addressstack 211. The pop delivers the address A_(N) on the location of thenext instruction to be loaded into the program counter for execution.

Were routine A and routine B translated as mentioned above to providecorresponding translated routines A′ and B′ (242 and 245) duringexecution of translated code in the native architecture, an instructionCall B′ would be encountered at 243. The shadow frame is allocated atthe beginning of a routine for all calls that the routine can make. Theinstruction Call B′ causes the shadow stack to be provided with a shadowstack frame 14 which comprises the four above-mentioned fields 20 a-20 dand the optional fields for local storage. Thus, in field 20 a isprovided the contents A_(N) of the stack pointer (SP) 17 of thenon-native return stack 11. This value corresponds to the location wherethe return address stored in the non-native return address stack 211 forthe corresponding native instruction execution will be found.

Likewise, stored in field 220 b is a copy of the non-native returnaddress that was pushed on the non-native stack by the execution of thecall instruction. The non-native return address is provided by thetranslated image and corresponds to the non-native call for theparticular call in the native or translated image. Here the non-nativeextended instruction pointer has a value corresponding to A_(N).Likewise, stored in field 220 c is the value of the native returnaddress A_(N)′. The dynamic link is stored in field 220 d whichcorresponds to the address of a preceding shadow stack frame header. Anew dynamic link is produced by saving the value of the shadow stackpointer prior to allocating a new frame. In location 218 is providedlocal storage for allocated variables provided during the translation ofthe corresponding routines A′ and B′ from the translator as mentionedabove.

Both the interpreter 44 (FIG. 3) and the translator 54 (FIG. 4) use theshadow stack 212 for determining the next instruction to be executedupon the processing of a return instruction. When translated code isexecuted in the computer system and a return instruction is encountered,a check is made to determine whether the code that followed the nativecall in the translator routine was well behaved.

That is, two assumptions are tested. The first is that the non-nativecode was well behaved with respect to the depth in the non-native returnaddress stack 211. The second assumption is that the code was wellbehaved with respect to the return address. If both of these conditionsare not satisfied then the code following the translated call cannot beexecuted and the instruction flow has to revert back to the interpreterfor continuing execution until such time as it encounters another callor return instruction or possibly a computed jump instruction.

These two conditions are determined by examining the value of thecontents of the non-native stack pointer SP as stored in location 220 ato determine whether it is equal to the contents of the non-native stackpointer 217. As mentioned above the non-native stack pointer 217corresponds to the current location on the non-native return addressstack 211. Thus this test is a measure of whether the non-native stack211 and the shadow stack 212 are at the same depth. The second check isto determine whether the return address stored in location 220 bcorresponds to the return address stored in the location in thenon-native return address stack 211 pointed to by the value of the SPpointer 217.

This check thus determines that the return address for the non-nativeinstruction is the same in the non-native stack 211 as well as theshadow stack 212. If this condition is not satisfied then theinterpreter changed the value of the return address. If either conditionis not satisfied, then execution is continued in the run-timeinterpreter 44 until such time as another call or return or computedjump instruction is encountered.

CALL ADDRESS TRANSLATION TABLE

Referring now to FIG. 24, a call address translation table 222 isproduced during translation of non-native code. As shown the calltranslation table 222 is appended to the translated code as in field221. The translated code 221 and the call address translation table 222provide the image 17 c referred to in FIG. 3. The table 222 includes apair fields one field 223 a corresponds to addresses or moreparticularly to address offsets from the starting address of calls fortranslated code routines and the other field 223 b corresponds toaddress offsets to the corresponding starting address in the non-nativearchitecture. The table 222 is here appended to the end of thetranslated image 221 as mentioned above.

Referring now to FIG. 25, the use of the shadow stack 212 as well as acall address translation table as mentioned above is illustrated. Asshown in FIG. 25, both table look-ups and shadow stack manipulations areused in the run-time interpreter 44 or a run-time translation system aswell as in the execution of translated code. Table look-ups are used foreach instance of a call instruction by the interpreter 44 or for eachinstance of execution of translated code. The shadow stack 212 is usedduring the processing of return instructions for the interpreter 44 aswell as during execution of calls in the translated code.

During execution of translated code there are two possibilitiesresulting from execution of a return instruction (RET). The firstpossibility shown as path 256 b is that the afore-mentioned test orcheck is passed and thus the return instruction can safely return andcontinue execution of translated code. The second possibility shown aspath 256 a is that if either one of the two checks fails, then executionreturns to the possibly updated address in the non-native stack andexecution continues or proceeds within the interpreter 44 until suchtime as a call, computed jump or a second return instruction isencountered.

Similarly, when the interpreter is executing native code in emulationmode, the interpreter likewise performs a check. A first path 258 awould be if there is no corresponding translated code available to beused by the interpreter. The second path 258 b would be taken if theinterpreter encounters a return address in which there is a validcorresponding translated routine. Thus, the shadow stack 212 permits theinterpreter to return to execution of translated code without requiringany corruptive or invasive modification of the non-native return addressstack 211.

Similarly, with table look-ups when a call 252 is encountered, theinterpreter 44 will perform a table look-up which, if there is acorresponding translated routine, will permit the translated code toexecute via path 252 b. Otherwise, the interpreter 44 will continueexecution via path 252 a. Similarly, the translated code when itperforms a call 254 will determine if there is a correspondingtranslated routine for the call and, if so, will permit execution viapath 254 b. Otherwise, control will be transferred back to theinterpreter via path 254 a.

By providing a shadow stack 212 which runs synchronous to the non-nativereturn address stack 211, several advantages are provided. The firstadvantage is that since the shadow stack 212 provides storage for nativereturn addresses and other information required in the native system, itis not necessary to place this information on the non-native returnaddress stack 211. Thus, the non-native return address stack 211 is notviolated or remains true to that which would occur during normalexecution of the non-native program in the non-native architecture.Amongst other things maintaining a true uninterrupted non-native stack211 permits a non-native exception handler to execute without anycomplex manipulation to remove native return addresses. In general, whenan exception occurs during execution of the native instructions theexception handler in the native architecture only expects to encounternative architecture instruction addresses. And similarly a non-nativeexception handler only expects to encounter non-native instructionaddresses.

Moreover, the shadow stack 212 being accessible to both the translatedcode and the interpreter 44 permits the interpreter to return controlback to translated code since the interpreter can use the shadow stackto determine a valid native return address which will continue executionof translated code. Without the shadow stack 212, therefore, it would benecessary either to place the native return addresses onto thenon-native return stack which is undesirable as mentioned above or tomake the unit of translation be limited to a basic block. As will bedescribed below this latter option is undesirable since it limits theopportunities for optimization of the translated code. Further, byhaving a non-native stack 211 and shadow stack 212, non-native returnaddresses can be separately managed from the native return addresses.This permits exception handlers for each image to properly handleproblems which caused an exception since the exception handlers do nothave to deal with return addresses associated with foreign code.

Referring now to FIG. 26, a translated routine 260 can have a call 260 awhich in turn has other calls 261 a to 261 c to other translatedroutines such as 262 a. Also in a translated routine 264, the routinecan encounter a switch/jump instruction 264 a which is a computed branchor jump to another routine such as routines 265 a to 265 c. Managementof the shadow stack 212 in conjunction with execution of translatedcode, execution in an original interpreter and activation of a newinterpreter will now be described.

SENTINEL SHADOW STACK FRAME

When a new interpreter activation initializes its native frame for theshadow stack, it pushes a sentinel shadow stack frame header onto theshadow stack 212. The stack pointer address is set at 7FFFFFFF, thelargest stack pointer possible, a value which will not be extended by anLDL instruction. This frame is needed for interpreter processing ofreturn instructions. The shadow stack frame return address field 220 cis set equal to 1 (a non-zero value) but is never used. The shadowdynamic link field 220 d is set equal to 0 to indicate that this is theinitial or sentinel frame on the shadow stack. The shadow stack extendedinstruction pointer is set to 0 and is never used.

During normal interpreter operation, that is, while the interpreter isexecuting instructions, it does not follow the stack pointer for theshadow stack. Thus, it does not push or place shadow frame entries ontothe shadow stack 212 even if the interpreter interprets non-native callsthat modify the non-native return address stack 211. If the interpreterencounters a non-native instruction call that calls a non-nativeinstruction routine that has been translated, however, then theinterpreter stores the instruction program counter onto the non-nativereturn address stack 211 as in normal operation and into the shadowstack 212. The interpreter 44 also performs a jump to the translatedroutine's interpreter entry point. The translated routine returns to theinterpreter 44 by jumping through one of its entry points as will bedescribed below.

Every translated routine has two entry points. One entry point is calledwhen the interpreter calls it and the other one is called when anothertranslated routine calls it. The entry points only differ in theadditional prologue or preparation that is performed when the routine isentered from another translated routine. When a translated routine isentered from another translated routine, the following occurs: Theregister which contains the native return address is stored into thereturn address field in the shadow stack for the particular shadow frameheader by executing an instruction

STL R26, 4(sp)

This instruction is executed before the shadow stack 212 is extended sothat the return address in the shadow stack 212 is always valid for allshadow frames 214 except the top one. This arrangement is required whenthe shadow frames 214 are discarded as a result of an exception orbecause execution had to resume in the interpreter. Next the executionfalls through to the interpreter entry point.

TRANSLATED ROUTINE ENTERED FROM INTERPRETER

When a translated routine is entered from the interpreter, the followinghappens: A shadow frame is produced for the translated routine. The sizeof the frame is 16 plus bytes where 16 is the number of bytes needed torepresent the header and the additional number of bytes are those usedto represent the local storage associated with the translated routine.The shadow frame header dylink field 220 d is set to the original stackpointer. The following instructions are executed:

MOV SP, T1 SUB SP, #<16+size>,sp STQ T1, (sp)

The shadow stack frame is produced using the above sequence.

When a translated routine executes a return instruction to returncontrol to its caller routine, the following occurs. Noting that thecurrent value of the non-native stack pointer points to the non-nativereturn address, the non-native return address is popped off of thenon-native return stack 211 into the non-native instruction pointer. Ifa “Return N′ instruction is being performed then also a pop of Nargument bytes from the non-native return stack is performed. Thefollowing instructions are used to execute these routines

MOV ESP, T1 LDL EIP, (esp) ADDL ESP, #<4+arg_bytes>, ESP

The previous shadow stack frame is located and the contents of thedynamic link are evaluated. Next the native code determines whether thenon-native stack pointer and the instruction pointer are the same asexpected by the caller. That is, the native code determines that thevalue of SP is equal to the contents of SP in the stack pointer 17 andthe value of IP is equal to the value of the return address stored atthe location pointed to by the stack pointer 17.

If these values are correct then the translated routine can returncontrol to the return address stored in the caller's shadow frame (i.e.,return control to another translated routine). If either of these checksfail however, then either the call was from the interpreter or thenon-native stack has been modified. In either case, execution is resumedin the interpreter after a potential clean-up of the shadow stack 212.The following instructions are used to perform the two checks:

LDQ T2, 8(T₀) Loads both gEIP and gESP SLL T1, #32, T1 The actual ESPbefore popping the non-native return address OR EIP, T1, T1; The actualEIP and ESP in a quad word SUBQ T1, T2, T1 LDL T3, 4(T₀) Load the nativereturn address in case it is needed BNE T1, $1 MOV T0, SP Actualdiscarded shadow frame RET (T3,)

where T0, T1, T2 and T3 are available registers in the nativearchitecture which would not interfere with the state of registers inthe non-native system.

TRANSLATED ROUTINE CALLS ANOTHER TRANSLATED ROUTINE

When the translated routine calls another translated routine, thefollowing occurs. The non-native return address is loaded into aregister and the register is pushed onto the non-native return stack 211and the non-native stack pointer is loaded into the non-native stackpointer field in the shadow stack 212. A jump to subroutine instructionis executed to the translated routine entry point placing the nativereturn address in a register. The translated routine executes until theroutine returns to its caller.

It is possible that the translated routine may never return to itscaller, for example, if the translated routine detects that thenon-native stack 211 has been modified. In this case, if the non-nativestack 211 has been modified the interpreter 44 will be entered to cleanup the shadow stack 212 and resume execution as mentioned above. If,however, the translated routine does return to its caller, thetranslated routine will have left the non-native state valid includingthe non-native stack pointer and will also have left the shadow stack212 valid insuring that it is in synchronization with the non-nativestack 211. Thus, the called translated routine can continue executing.

If a translated routine calls a routine that has not been translated, itthen enters the interpreter. The non-native return address is passed toa register in the interpreter 44 and the contents of the register arepushed onto the non-native return address stack 211. This corresponds tothe non-native return address. The contents of the register are alsoloaded into the non-native extended instruction pointer field in theshadow stack 212. The extended stack pointer 217 which points to thenon-native return address just pushed onto the non-native return stackis itself loaded into the non-native extended stack pointer field 20 ain the shadow stack 212. The non-native address of the routine beingcalled is then loaded into the non-native instruction pointer and a jumpto subroutine instruction is executed to the interpreter entry point. Alook-up call entry is performed placing the native return address instack pointer 217. The interpreter the stack pointer 217 stores register226 in the native return address field 220 c of the shadow stack 212 andexecutes until the interpreter 44 interprets a return instruction.

TRANSLATED ROUTINE CALLS JACKETED ROUTINE

If a translated routine calls a jacketed routine, the following occurs.A jump to subroutine instruction to the jacketed routine entry point isperformed placing the non-native return address in the non-native stackpointer 217. The jacketed routine produces a native frame and executesthe native routine. Since only operating system supplied entry pointsare jacketed, these are known to be well-behaved and thus will not altertheir return address. Therefore, the non-native stack pointer or thenon-native instruction pointer in the shadow stack are not saved andthere is no check performed on them before returning from the jacketedroutine.

If the jacketed routine performs a call back, then another interpreteractivation native frame will be produced and a separate shadow stackwill be managed. When the call back returns, the interpreter activationnative frame will be removed together with the now empty shadow stack.When the jacketed call returns, it will remove its native frame leavingthe stack frame pointing again to the top shadow frame of the previousinterpreter activation. As with the above, the jacketed routine maynever return to its caller. For example, an exception may occur thatcauses the call back interpreter to be exited and non-native framesdiscarded. This will cause the shadow stack 212 to be cleaned up. If,however, it does return to its caller the jacketed routine will haveleft the non-native state valid including the non-native stack pointer217. It will also have left the shadow stack 212 valid insuring that itis in sync with the non-native stack 211. Therefore, the callertranslated routine can continue executing.

ENTRY TO INTERPRETER DUE TO INDIRECT JUMP OR SWITCH

A translated routine can also enter the interpreter due to an unknownindirect jump. If translated code performs a jump to a target that isnot statically known, for example, indirect jump to a target not listedin the profile information, then the translated routine is abandoned andexecution continues in the interpreter 44.

RETURNING TO TRANSLATED CODE

The interpreter also makes decisions as to whether it can return totranslated code. The interpreter also checks when interpreting a returninstruction that returning to a translated routine is valid. Theinterpreter saves the current value of the non-native stack pointer thatpoints to the non-native return address on the non-native stack 211 andpops the non-native return address from the non-native stack 211 intothe non-native instruction pointer. If a Return N instruction is beingperformed then it also pops N number of argument bytes from thenon-native stack 211. The interpreter then checks the value of thenon-native stack pointer and the non-native instruction pointer todetermine that they are the same as those stored in the shadow stackframe 214. If they are the same then control can be returned safely tothe return address which is stored in the shadow stack 212 and executionof translated code can resume. If they are not the same, then the shadowstack 212 needs to be cleaned-up and control returned to theinterpreter. If no translated code exists in the shadow stack, then thesentinel shadow stack frame ensures that control remains in theinterpreter and there is no need to clean up the shadow stack.

SHADOW STACK FRAME CLEAN-UP

The interpreter clean-up shadow stack frame routine is invoked onre-entry from translated code when it is detected that the shadow stack212 is out of synchronization with the non-native stack 211. The cleanup shadow stack frame routine discards orphaned shadow stack frames 214.The approach is to discard shadow stack frames 214 until the value ofthe extended stack pointer stored in the non-native extended stackpointer field 220 a is greater than the value of the extended stackpointer.

OBJECTS AND OBJECT MANAGEMENT BETWEEN DISSIMILAR ENVIROMENTS

Object oriented programming systems support the definition and use of“objects.” An object in such a system is a data structure combined witha set of “methods” or “functions” available to manipulate the datastored within that data structure.

Referring now to FIG. 27, an example of an object 300 is shown includinga first interface, Interface 1 300A, a second interface, Interface 2300B and a third interface, IUnknown 300C. The interfaces to the objectare drawn as plug-in jacks. When a client wishes to use the object 300,it must do so through one of the interfaces shown. The actual contentsof the object being manipulated can only be accessed through one of theinterfaces provided for that object. Each of the interfaces 300 a and300 b are also objects themselves.

Referring now to FIG. 28, there is shown an example of a client 301 a(which can be another process running on the system 10 or another systemsuch as in a networked system not shown) accessing an interface of anobject 302 c. FIG. 28 shows the client 301 a calling an object interfaceof the object 302 c. The client 301 a obtains a pointer 301 f to aninterface 301 c of an object proxy 301 b. For an example of how apointer to an interface object is obtained see FIG. 30. Informationregarding the interfaces of an object is obtained through a queryfunction defined or provided by the service architecture. For examplethe function QueryInterface in the OLE® (Object Linking and Embeddingproduct of Microsoft Redmond Wash.) service architecture is used forthis purpose.

The present system supports operations on objects that are eitherin-process, local or remote with respect to the client. The addressspace of the client is the set of all possible addresses provided by theoperating system to the process in which the client executes. Anin-process object therefore is an object located within the same addressspace as the client. A local object is an object located on the samecomputer system as the client, but not in the same address space. Aremote object is an object that is located on a different computersystem than that which the client is located on.

In the example of FIG. 28, the object being referenced is local orremote to the client. The interface 301 c is an in-processimplementation of the desired interface as part of an in-process objectproxy 301 b. In an alternative example of operation of the presentsystem, where the object being referenced is in-process, the in-processimplementation referenced by the client is the object implementation ofthe interface itself. In that alternative example the call by the clientto the desired object interface is a local call to the objectimplementation of the interface.

During operation of the example embodiment shown in FIG. 28, the clientprocess 301 communicates with a server process 302 by an inter-processcommunication facility, for example a remote procedure call facility 301e. Within the client process 301 there is shown a client 301 a, whichuses an interface 301 c to access an object proxy 301 b. The objectproxy is further shown having a second interface 301 d.

The server process 302 is shown including an object 302 c and a stubroutine 302 a which accesses the object 302 c through an interface 302d. The stub routine 302 a processes client requests received via theinter-process communication facility. The stub routine 302 a furtherexecutes a local procedure call within the server process 302 to theobject interface 302 d. The object 302 c is also shown having aninterface 302 e. The interfaces 302 d and 302 e include object functionswhich are used by the client 301 a to operate on the data included inthe object 302 c itself.

The client 301 a accesses the object interface 302 d by referencing theobject proxy 301 b through the interface 301 c. The object proxy 301 buses the remote procedure call function 301 e to send a message to thestub routine 302 a. The stub routine 302 a uses object functions withinthe interface 302 d to operate on the actual object within the serverprocess 302 b. The stub routine 302 a sends the results of operations onthe object 302 c back to the object proxy 301 b through the remoteprocedure call utility 301 e. The object proxy 301 b returns the resultsof the operations on the object 302 c to the client 301 a through theinterface 301 c.

Also during operation of the elements shown in FIG. 28, when the client301 a calls a function of the interface 301 c, the object proxy 301 btakes all the arguments to that function of the interface 301 c, andpackages them in a portable data structure. The stub routine 302 a inthe server process 302 maintains an interface pointer to the object 302c and receives the call through the remote procedure process 301 e. Stubroutine 302 a pushes the arguments from the call onto the server processstack as needed and makes the call to the implementation of the functioncalled by the client in the actual object 302 c through the interface302 d. When that call returns, the stub routine 302 a packages thereturn values and any out-parameters and sends them back to the objectproxy 301 b. The object proxy 301 b then unpacks the information andreturns it to the client 301 a.

An “execution engine” is an implementation of a computer architecture onwhich code for that computer architecture may be executed. A firstexample of an execution engine is a hardware implementation, such as amicroprocessor or CPU implementing the processor architecture for whichthe code was designed and developed. A second example of an executionengine is a software emulation of a processor architecture, referred toas a “simulator” or an “emulator”. In another example of an executionengine, non-native program code is translated by interpreter software atrun-time into code that is executable on the underlying hardware systemand then executed on the underlying hardware system.

MULTICODE EXECUTION ENVIROMENTS

In a multi-code execution environment, where native code for a firstcomputer architecture is executing such as the computer system 10(FIG. 1) as well as non-native code for a second computer architecturesuch an a non-native image interpreted by the interpreter 44 (FIG. 3),the client process 301 and the server process 302 may be executing onexecution engines for dissimilar architectures. For example, the clientprocess 301 may be executing on the system 10 in native mode, while theserver process 302 may be executing in the interpreter 44 (or otheremulation environment), or vice versa.

Referring now to FIG. 29, an interface structure 307 for an object isshown. The interface structure 307 provides an implementation of each ofa plurality of member functions through an array of pointers to themember functions. The array of function pointers is referred to as the“vtable” or “virtual function table”.

In FIG. 29 a pointer 303 is shown pointing to an interface object 304.The interface object 304 includes a pointer 304 a to an interfacefunction table 305 and a private object data region 304 b. The interfacefunction table 305 is shown having pointers 305 a through 305 f tofunctions 1 through 6. The pointers 305 a through 305 f in interfacefunction table 305 point to implementations of the interface functions306. The number of pointers shown here six (6) is for purposes ofexample only, and other numbers of functions may be used for variousspecific interfaces.

In a multicode execution environment, the user of a given interfacefunction accesses that interface function using the pointer 303 to theinterface object 304. However, the implementation of interface functions306 may be for an architecture dissimilar to the architecture which theexecution engine of the user or client of the object supports.

The interface function table 305 is shared among all instances of aninterface object. In order to differentiate each interface instance, anobject allocates according to the object's internal implementation asecond structure that contains private object data 304 b for eachinterface instance. In the example of FIG. 29, the first four bytes ofinterface object 304 are a 32-bit pointer to the interface functiontable 305, followed by whatever private data 304 b the interface objecthas. The pointer 303 to the interface object 304, is thus a pointer to apointer to the interface function table 305. It is through the pointer303 to the interface object 304, referred to herein also as an“interface pointer” or “pointer to an interface”, that a client accessesthe object implementation of the interface methods, also referred toherein as the “interface member functions”.

The client may not access the interface object's private data 304 b. Theelements of FIG. 29 are an example of a structure that C++ compilers maygenerate for a C++ object instance. To access an interface to an object,and thus apply the interface functions to an object instance, a clientmust obtain a pointer to the interface, for example interface pointer303.

OPERATION IN OBJECT ORIENTED SERVICE SYSTEM

Now referring to FIG. 30, a sequence of steps to use an object in anobject oriented service system is shown. In step 307 an object isentered into a system registry. The system registry may for example bepart of the operating system (not shown) of the computer system on whichthe client is executing. Step 307 may occur for example either at runtime or at system build time. If the entry is made at build time, thenthe object is known by the system registry prior to the client startingup. This is known as “static registration”. Where the object class isestablished at run time and is known locally to the client process thisis known as “dynamic registration”. For example, dynamic registration isaccomplished by a call to a dynamic registration service function, as inthe OLE service architecture by use of the CoRegisterClassObjectfunction.

Following step 307, in step 309, if the registration from step 307 isstatic, the registry is searched based on a user input to obtain a classidentifier (“ClassId”). For example, a user may provide an input througha graphical user interface (GUI) indicating to the system that theregistry should be searched for information regarding a previouslyregistered object class. If the registration from step 307 is dynamic,then the ClassId of the object class is known by the client as a resultof a call to the dynamic registration service function for the servicearchitecture.

Alternatively to steps 307 and 309, a client may have informationregarding the object class in question included in an “include file”within the client's implementation in step 308. For example thisinformation may be a class identifier for a particular class of objectswhich the client wishes to instantiate and access at run time. Step 308occurs at compile time.

The output of steps 307 and 309, or alternatively step 308, is a classidentifier 310. The class identifier 310 is used by the client to obtainan instance of an object for the client to use. Step 311 shows anexample embodiment of the steps required to obtain an object instance.In substep 311 a a pointer is obtained to an interface used to createinstances of the object identified by the class identifier 310. Forexample in the OLE service architecture an interface known asIClassFactory is used to obtain instances of an object. In the OLEsystem, for purposes of example, a pointer to IClassFactory is obtainedby calling the OLE service OleGetClassObject in substep 311 a. Theinterface to IClassFactory is then used to create an object instance ofa particular class identified by the class identifier 310.

Subsequent to substep 311 a, in substep 311 b the client creates aninstance of the object by invoking a function of the interface obtainedin substep 311 a. In OLE, for example, the function invoked isIClassFactory::CreateInstance. The output of substep 311 b is a pointerto an interface. The interface pointer is shown as 312 in FIG. 30. InOLE the interface pointer obtained is a pointer to the IUnknowninterface, which is required to be present in all OLE object interfaces.

After obtaining the interface pointer 312, the client uses the interfacepointer to learn and invoke object methods on the instance of the objectcreated in step 311. As shown in FIG. 30, in order to use an object aclient first obtains a class identifier, either through a registrationsystem, or through compile time information such as include files. Thenext step necessary for a client to use an object is for the client tocreate an object instance. Once the object instance is created, forexample, in step 311, a pointer to an interface of the object is thenavailable to the client. The interface pointer is necessary for theclient to access the object, since an object may only be accessedthrough one of its interfaces. Finally, after a client has obtained aninterface pointer, that interface pointer may be used to invoke objectmethods on the object instance in step 313.

JACKETTING AND INTERFACE STRUCTURE REPLACEMENT

Referring now to FIG. 31, steps in an example embodiment of a method forintercepting functions in order to perform interface structurereplacement are shown. The steps are performed to replace the interfacestructure shown in FIG. 29 with a replacement interface structure shownin FIG. 32. The steps of FIG, 31 further perform general functionjacketing with respect to the intercepted function. In an exampleembodiment, the steps of FIG. 31 are performed by the jacketing routine48 (FIG. 3).

At step 320 the jacketing routine 48 detects a function call having aninterface object pointer as a parameter. The set of function callshaving an interface object pointer as a parameter is determined prior torun time. In an example embodiment of FIG. 31, the set of function callshaving an interface object pointer as a parameter, and which thereforeare detected by the jacketing routine 48 in step 320, include all OLEApplication Programming Interface calls (OLE APIs) and all calls to OLEStandard Interface functions. The names of the OLE APIs and OLE StandardInterface functions are determined and passed to the jacketing routine48 prior to run time. For example the names of the function calls havingan interface object pointer as a parameter are built into the jacketingroutine 48, for example at compile time through an include file. Thenames and descriptions of functions having an interface object pointeras a parameter may be determined from documentation available from themanufacturer, dealer or developer of the object based servicearchitecture. The run time addresses of these functions are madeavailable to the jacketing routine 48 and the jacketing routine 48 isinvoked upon any transfer of control to one of these functions in step320.

Other examples of function calls detected by the jacketing routine 48 instep 320 are those functions in the object service architecture whichenter an object class into a system registry, functions which search thesystem registry and return a ClassId of an object class, or functionswhich create an object instance. These functions include those shown inFIG. 30 as 307, 309, and 311 respectively. Thus in step 320 functionswhich have an interface object pointer as a parameter are detected sothat interface structure replacement can be performed. If a functioncall is intercepted in step 320 which does not take an interface objectpointer as a parameter, no interface structure needs to be replaced andtherefore no replacement is performed by the jacketing routine 48.

In step 322, following step 320, the jacketing routine 48 determines howthe interface object pointer parameter is used by the function calldetected in step 320. The exact usage of the interface object pointerparameter for each function having an interface object pointer parameteris determined prior to run time and incorporated into the jacketingroutine 48. For example, the jacketing routine 48 may include a list ofargument templates describing the format and use of arguments in thefunction calls intercepted in step 320. Such argument templates may forexample be developed a priori from information regarding the functioncalls intercepted in step 320 contained in documentation or source codefrom the manufacturer, dealer or developer of the object based servicearchitecture. In an alternative embodiment, the argument templates aredeveloped at run time based on information obtained regarding thefunction calls intercepted in step 320 from a type information serviceprovided by the object service architecture.

In an example embodiment each argument template describes whether theinterface object pointer is an “input-only”, “input-output”, or“output-only” parameter. An input-only parameter is passed to thefunction, but is not modified or passed back from the function. Aninput-output parameter is passed to the function and replaced ormodified before the function completes. And an output-only parameter iswritten or passed back from the function call without regard to itsinput value. In step 322 of FIG. 31 the jacketing routine determineswhether the interface pointer parameter is input-only, input-output, oroutput-only, based on information in the argument template for theintercepted function.

At step 323 the jacketing routine 48 branches to step 324 if theinterface pointer parameter is input-only or input-output. If theinterface pointer parameter is not input-only or input-output, step 323is followed by step 326. In step 324 the interface structure indicatedby the interface pointer parameter is replaced with the replacementinterface structure shown in FIG. 32.

In step 326 the original function detected in step 320 is called by thejacketing routine 48. During step 326 general function jacketing isperformed by the jacketing routine 48. General function jacketing isdescribed in FIG. 40.

At step 328 the jacketing routine 48 branches to step 329 if theinterface object pointer parameter was either output-only orinput-output. If the interface object pointer parameter was not outputonly or input-output, then the jacket function 48 is done for thisintercepted function after step 328. In step 329 the jacketing routine48 replaces the interface structure of the interface pointed to by theinterface object pointer parameter with the replacement interfacestructure shown in FIG. 32.

REPLACEMENT INTERFACE STRUCTURE

Referring now to FIG. 32, an example embodiment of the replacementinterface structure provided by the jacketing routine 48 as described insteps 324 and 329 in FIG. 31 is shown. The example shown in FIG. 32includes an interface pointer 334, pointing to the top of an interfaceobject 336. The interface object 336 includes a pointer 336 a to aninterface function table, as well as private object data 336 b. Thepointer 336 a points to the first of one or more jacket functions, forexample 338 d, within a replacement interface function table 338.

The replacement interface function table 338 includes a pointer to theoriginal function table 338 a, a signature 338 b indicating theprocessor architecture for which the object was originally created, anarea 338 c reserved for use by a system wide remote procedure callutility, a pointer 338 d to a jacket function for function 1 in theoriginal interface function table, and pointers 338 e through 338 h tojacket functions for other functions in the original interface functiontable. The pointer 338 a to the original interface function table pointsto the top of the original interface function table shown as 340. Theoriginal interface function table contains pointers 340 a through 340 hto the object implementation of the interface functions 342.

During operation of the jacketing routine 48 shown in FIG. 3, thereplacement interface structure shown in FIG. 32 is used to replace theoriginal interface structure based on the function interceptiondescribed in connection with FIGS. 31, 38 and 39. Subsequent toreplacement with the replacement interface structure, clients executingin a first architecture (Architecture A), for example system 10 on whichthe code is being executed, may invoke functions for objects implementedin a second architecture (Architecture B), for example non-native code.Similarly, non-native code may invoke functions for objects created innative code. During operation of the disclosed system the replacementinterface structure shown in FIG. 32 allows for multi-code operation ofobject methods that is transparent to the user.

The following “Interface Signatures Table” (TABLE II) shows replacementinterface structure signatures in the middle column, and indicates thefunctionality of jacket functions pointed to by replacement interfacefunction tables for each replacement interface structure signature:

TABLE II Code Environment Replacement Code Environment Where InterfaceInterface Where Interface Referenced Signature Created Architecture BPAJB Architecture A Architecture A PAJB Architecture A Architecture BPBJA Architecture B Architecture A PBJA Architecture B

The replacement interface structure signatures in the InterfaceSignatures Table are shown as character strings for purposes of example,and other encodings are possible. The left most column indicates thearchitecture of the execution engine from which an interface isreferenced. The middle column shows the signature of the replacementinterface function table for that interface. The signature in the middlecolumn indicates the functionality of jacket functions pointed to by thereplacement interface function table.

The right most column indicates the processor architecture for which theinterface and its object functions was originally created. The presentsystem determines the processor architecture for which the interface wasoriginally designed as follows: When a call is intercepted to a functionhaving a parameter equal to a pointer to an interface object, theintercepting process of the present invention, for example the jacketingroutine 48, determines whether the interface structure has already beenreplaced. This determination is made by checking the signature field inthe interface structure. If the signature field contains either thestring PAJB or PBJA, then the interface structure has been replaced, andno further replacement is performed.

If no interface replacement has been performed, then a replacement isperformed. When an interface structure is replaced the replacing processdetermines the signature of the replacement interface structure based onthe processor architecture of the execution engine from which the callhaving a parameter equal to an interface object pointer was made. If thecall was made from an execution engine for Architecture A, and noreplacement has previously been made, then the object interfacefunctions were designed and developed for use on the execution enginefor Architecture A. This follows because an object instance mustinitially be created in order for operations to be performed on objectdata within the instance, and object creation involves use of functionsthat are intercepted by the present system.

The first two rows in the Interface Signatures Table show the case inwhich the processor architecture for which the interface was originallycreated is Architecture A. The middle column entries in those rowsindicate that when a replacement interface function table is providedfor an interface that was designed for Architecture A, the signaturestring for that replacement interface function table is “PAJB”. Thuswhen an object interface was originally designed for Architecture A, thejacketing routine 48 in FIG. 3 writes a signature code of “PAJB” intothe signature field of a replacement function table provided asdescribed in steps 324 and 329 in FIG. 31.

The signature code indicates the functionality of the jacket functionspointed to by the replacement interface function table. If the signaturecode in a replacement interface table is “PAJB” then if a subsequentreference is made to the interface object from code executing in anexecution engine for Architecture B (as in the first row of the table),the call to the original interface function is jacketed (through generalfunction jacketing) by the jacket function. If the reference to theobject is made from code executing under the execution engine forArchitecture A (as in the second row), then the original interfacefunction is passed through to the execution engine for the code makingthe reference. Passing the original interface function through permitsit to execute at maximum speed without general function jacketingoverhead. The signature code PAJB is an acronym standing for “PassThrough A-Jacket B”.

In rows 3 and 4 of the table, the replacement interface signature isPBJA, an acronym for “Pass Through B, Jacket A”. This interfacesignature is included in a replacement interface function table when thecode environment the interface was designed for is Architecture B. Ifthe interface is subsequently referenced by code executing on anArchitecture B execution engine (as in the case shown by row three),then the jacket functions pointed to by entries in the replacementinterface function table pass through the original function to theArchitecture B execution engine in order that it may execute at maximumspeed without unnecessary general function jacketing. If the interfaceis referenced from an Architecture A execution engine (as in row four),then the jacket function performs general function jacketing on the callto the original interface function in order that the original interfacefunction may execute correctly.

MULTI-ARCHITECTURE INSTRUCTIONS

In FIG. 33 there is shown an example design template for a jacketfunction. A pointer 350 to a jacket function is shown, corresponding tothe pointers shown in FIG. 32 as elements 338 d through 338 h. Thepointer 350 points to the entry point label From_Table 352. Two otherentry point labels are shown, specifically ARCHB 355 and 354 ARCHA.

At the entry point From_Table 352, there is shown a “multi-architectureinstruction” 353 (Instruction X) which is executable by executionengines for both Architecture A and Architecture B. In an exampleembodiment of the invention, where Architecture A is an Alpha system,and Architecture B is an X86 type system, the binary value of themulti-architecture instruction INSTX 353 is 0x23FFxxEB. In an Alphasystem this binary value defines the following Alpha instruction:

LDA R31, {{ARCHB−{From_Table +2} &255}<<8}+0xEB(R31)

This “LOAD ADDRESS” instruction consumes 4 bytes and is an operationwhich has no effect (referred to as a “NO-OP”) because it writes(“loads”) register 31, generates no exceptions, and does not accessmemory. In the Alpha architecture, register 31 is hardwired to zero, andwrites to register 31 have no effect. Accordingly the value of the bytes“xx” are not relevant when the instruction executed by the Alphaexecution engine. Thus when executed by the Alpha execution engine themulti-architecture instruction INSTX 353 has no effect on the value ofregister 31, which is always zero. Control passes to the nextinstruction following the multi-architecture instruction INSTX 353 atthe entry point label ARCHA 354.

The above instruction INSTX 353 is defined by the X86 processorarchitecture as the jump instruction below:

JMP xx

where ARCHB is a predetermined byte offset for the “JUMP IMMEDIATE BYTE”instruction having opcode EB (hex). The predetermined byte offset iscalculated to result in a jump to the entry point ARCHB.

When the instruction INSTX 353 is executed by an Architecture B (Intel)execution engine, it is an unconditional branch immediate instructioncausing a branch of control to an instruction located at an offset fromthe current instruction address. The byte displacement for the branch isfound in the next to lowest byte, and is shown for purposes of exampleas the “xx” bytes. Therefore the value of the “xx” bytes is made equalto the offset of the entry point ARCHB 355. The entry point ARCHB 355 isthus “xx” bytes lower (if the offset is negative), or “xx” higher (ifthe offset is positive) than the multi-architecture instruction 353.After the multi-architecture instruction 353 is executed by theArchitecture B execution engine, control is passed to the instructionlocated at the ARCHB entry point 355.

In an alternative embodiment, the multi-architecture instructionInstruction X is one which generates an exception when executed byeither the Architecture A or Architecture B execution engine. Forexample Instruction X may be an instruction which causes an accessviolation by attempting to access an out of bounds memory location. OrInstruction X may be a binary value containing an illegal instructionresulting in an illegal instruction exception. In this alternativeembodiment, the exception handler(s) for the exception generated byInstruction X determines that the cause of the exception was attemptedexecution of Instruction X. The exception handler then determines whichexecution engine was executing at the time of the instruction. If theexecution engine was for Architecture A, then the exception handlertransfers control to the entry point ARCHA. If the execution engine wasfor Architecture B, then the exception handler transfers control to theentry point ARCHB.

The functionality of the code following the ARCHB entry point 355 andthe multi-architecture instruction 353 (ARCHA) depends on whether theoriginal object (and its interface functions) was developed forArchitecture A or Architecture B. The various combinations of stepsfound in these sections of code are described in FIGS. 34 to 37.

FIG. 34 shows steps performed by the code in a PBJA jacket function atthe entry point ARCHB shown as element 355 in FIG. 33. The steps of FIG.33 “pass through” the original call to the execution engine of thecaller without performing general function jacketing. In step 356 thecode begins at the entry point ARCHB. The jacket function is thereforebeing called from code executing on an Architecture B execution engine.As described above the processor architecture of the caller may bedetermined using a multi-architecture instruction as shown in FIG. 33.

In step 357 the jacket function determines whether the original functionbeing called is one that takes an interface object pointer as either aninput-only or input-output parameter (as in steps 320 through 323 inFIG. 31). This determination is made for example based on apredetermined list of functions which take an interface object pointeras a parameter, as well as associated argument templates for each of thelisted functions describing how the arguments to the function are used.In an alternative embodiment, the argument template may be obtained atrun time from an object type information service provided by the objectbased service architecture.

If the original function takes an interface object pointer as either aninput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure does not contain either PBJA or PAJB then the interfacestructure has not been replaced and replacement is performed.Accordingly if replacement is performed step 357 is followed by step358. Otherwise, step 357 is followed by step 359. In step 358 theinterface structure of the interface object pointer parameter isreplaced with a PBJA replacement interface structure as shown in X+5.The signature is PBJA because the code making the reference is executingon the Architecture B execution engine, and therefore the interface wasdesigned for execution on an Architecture B execution engine.

In step 359 the jacket function reads the pointer to the originalfunction from the original function table. A pointer to the originalfunction table is contained in the replacement interface function table.In step 360 the jacket function calls the original function. No generalfunction jacketing is performed in step 360.

In step 361 the jacket function determines whether there is an interfaceobject pointer parameter to the original function that is either anoutput-only or input-output parameter (as in step 328 in FIG. 31). Thisdetermination is made for example based on a predetermined list ofobject methods or functions which take an interface object pointer as aparameter, as well as associated argument templates for each of thelisted functions describing how the arguments to the function are used.For example where the object based service architecture for the systemis OLE, then the list of OLE Standard Interface functions is used toconstruct the predetermined list of object methods having an interfaceobject pointer as a parameter. In an alternative embodiment, theargument template may be obtained at run time from an object typeinformation service provided by the object based service architecture.

If the original object function takes an interface object pointer aseither an output-only or input-output parameter, then the jacketfunction determines whether the signature field of the interfacestructure contains either PBJA or PAJB. If the signature field of theinterface structure contains either PBJA or PAJB then the interfacestructure has not been replaced and replacement is performed.Accordingly, if replacement is performed then step 361 is followed bystep 362 in which the interface structure for the interface objectpointer parameter is replaced by a PBJA replacement interface structure.Otherwise, step 361 is followed by step 363 which returns to theoriginal caller.

FIG. 35 shows the steps performed by a jacket function pointed to by apointer in a replacement interface function table, where the replacementinterface function table signature field value is “PBJA.” The steps areperformed by software following the entry point ARCHA: as shown in FIG.33.

The software performs general function jacketing. General functionjacketing is further described in connection with step 326 in FIG. 31above. The label ARCHA: is shown as element 366 in FIG. 35.

At Step 368 the jacket function determines whether it is necessary toperform interface structure replacement. Step 368 determines whetherinterface structure replacement is necessary by determining whether anyof the parameters to the function associated with the jacket functionare pointers to interface objects, and are either input-only orinput-output. This determination is made for example based on apredetermined list of standard interface functions which take aninterface object pointer as a parameter, as well as associated argumenttemplates for each of the listed functions describing how the argumentsto the function are used. An example of the predetermined list ofstandard interface functions would include the OLE Standard Interfacefunctions. In an alternative embodiment, the argument template may beobtained at run time from an object type information service provided bythe object based service architecture.

If the original function takes an interface object pointer as either aninput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure does not contain either PBJA or PAJB then the interfacestructure has not been replaced and replacement is performed.Accordingly if replacement is performed step 368 is followed by step369.

In step 369 the PBJA jacket function performs interface structurereplacement, replacing the interface structure of the interface objectpointed to the by the interface object pointer parameter with areplacement interface object structure as shown in FIG. 32, and having asignature value equal to “PAJB”. The signature value is PAJB because thecode referencing the interface was executing on an Architecture Aexecution engine.

In step 370 the PBJA jacket function reads the function pointer of theoriginal function from the original function table. The originalfunction table is accessed through a pointer to the original functiontable in the replacement interface function table. In step 371, the PBJAjacket function calls and performs general function jacketing on theoriginal function.

In step 372 the PBJA jacket function determines whether interfacestructure replacement is necessary as to any of the output parameters ofthe original function. Interface structure replacement is necessary forany interface object pointer parameters to the function that areoutput-only or input-output. This determination is made for examplebased on a predetermined list of standard interface functions which takean interface object pointer as a parameter, as well as associatedargument templates for each of the listed functions describing how thearguments to the function are used. In an alternative embodiment, theargument template may be obtained at run time from an object typeinformation service provided by the object based service architecture.

If the original function takes an interface object pointer as either anoutput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure contains either PBJA or PAJB then the interface structure hasnot been replaced and replacement must be performed. Accordingly, ifreplacement must be performed then step 372 is followed by step 373.Otherwise step 372 is followed by Step 375.

In Step 373, the PBJA jacket function performs interface structurereplacement by replacing the interface structure of the object pointedto by the output interface object pointer parameter to the function withthe replacement interface structure shown in FIG. 33, and including thesignature “PBJA” into the signature field of the replacement interfacefunction table. The signature is PBJA because the interface was returned(output) from an execution engine for Architecture B in step 371. Atstep 375 control is passed to the original caller of the function.

FIG. 36 shows the steps performed by a jacket function in a “PAJB”replacement interface structure. The steps are performed by software ina jacket function following the entry point ARCHA: as shown in FIG. 34.The entry point ARCHA: 380 is followed by step 381. In step 381 PAJBjacket function determines whether interface structure replacement isnecessary. Interface structure replacement is determined to be necessaryat step 381 if the original function takes an interface object pointeras an input-only or input-output parameter. This determination is madefor example based on a predetermined list of standard interfacefunctions which take an interface object pointer as a parameter, as wellas associated argument templates for each of the listed functionsdescribing how the arguments to the function are used. In an alternativeembodiment, the argument template may be obtained at run time from anobject type information service provided by the object based servicearchitecture.

If the original function takes an interface object pointer as either aninput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure does not contain either PBJA or PAJB then the interfacestructure has not been replaced and replacement is performed. Ifinterface structure replacement is determined to be necessary in step381, step 381 is followed by step 382. Otherwise step 381 is followed bystep 383.

At step 382 the PAJB jacket function performs interface structurereplacement by replacing the interface structure for the interfaceobject pointer parameter with a replacement interface structure as shownin FIG. 32 having signature field value equal to “PAJB”. The signatureis PAJB because the interface was referenced from code executing on anArchitecture A execution engine and the interface was determined to nothave been previously replaced by examination of the signature field.

In step 383, the PAJB jacket function reads the function pointer to theoriginal function from the original function table. The originalfunction table is located through a pointer to the original functiontable contained in the replacement interface function table.

In step 384, the PAJB jacket function calls the original function. Nogeneral function jacketing is performed in step 384. The originalfunction executes on the Architecture A execution engine.

In step 385 the PAJB jacket function determines whether interfacestructure replacement is necessary following the return of the call tothe original function. The determination of step 385 is made by checkingto see if the original function had an interface object pointerparameter that was either output-only or input-output. Thisdetermination is made for example based on a predetermined list ofstandard interface functions which take an interface object pointer as aparameter, as well as associated argument templates for each of thelisted functions describing how the arguments to the function are used.In an alternative embodiment, the argument template may be obtained atrun time from an object type information service provided by the objectbased service architecture.

If the original function takes an interface object pointer as either anoutput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure contains either PBJA or PAJB then the interface structure hasnot been replaced and replacement must be performed. Accordingly, ifreplacement must be performed then step 385 is followed by step 386.Otherwise, step 385 is followed by a return 387 to the original caller.

In Step 386 the PAJB jacket function performs interface structurereplacement by replacing the interface structure for the outputinterface object pointer parameter with a replacement interfacestructure as shown in FIG. 32 having a signature field value equal to“PAJB”. The signature is PAJB because the interface had not beenreplaced and the code returning (outputting) the object pointer wasexecuting on an Architecture A execution engine.

FIG. 37 shows the steps of the code executed by a jacket function in areplacement interface structure having a signature field value equal to“PAJB”, when a function in the interface is called from code executingunder an execution engine for Architecture B. FIG. 37 includes stepsperformed by software stored following entry point ARCHB:.

In step 392, the PAJB jacket function determines whether interfacestructure replacement is necessary. The PAJB jacket function makes thisdetermination by determining whether the originally called functionincludes a parameter that is an interface object pointer which is eitheran input-only or in-out parameter. This determination is made forexample based on a predetermined list of standard functions which takean interface object pointer as a parameter, as well as associatedargument templates for each of the listed functions describing how thearguments to the function are used. In an alternative embodiment, theargument template may be obtained at run time from an object typeinformation service provided by the object based service architecture.

If the original function takes an interface object pointer as either aninput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure does not contain either PBJA or PAJB then the interfacestructure has not been replaced and replacement must be performed.Accordingly if replacement must be performed step 392 is followed bystep 393. Otherwise step 392 is followed by step 394.

In step 393 the PAJB jacket function performs interface structurereplacement by replacing the interface object structure pointed to bythe interface object pointer parameter with a replacement interfacestructure as shown in FIG. 32 and having a signature field value equalto “PBJA”. The signature is PBJA because the interface had not beenreplaced and the code making the reference to the interface wasexecuting under the Architecture B execution engine.

In step 394 the PAJB jacket function obtains the function pointer to theoriginal function from the original function table. The originalfunction table is accessible to the PAJB jacket function through apointer to the original function table found in the replacement functiontable. In step 395 the PAJB jacket function performs general functionjacketing and calls the original function for the interface.

In step 396 the PAJB jacket function determines whether interfacestructure replacement is necessary after the return of the originalfunction. If the original function took as a parameter an interfaceobject pointer that was either an output-only or input-output parameter,then interface structure replacement is necessary. This determination ismade for example based on a predetermined list of standard interfacefunctions which take an interface object pointer as a parameter, as wellas associated argument templates for each of the listed functionsdescribing how the arguments to the function are used. In an alternativeembodiment, the argument template may be obtained at run time from anobject type information service provided by the object based servicearchitecture.

If the original function takes an interface object pointer as either anoutput-only or input-output parameter, then the jacket functiondetermines whether the signature field of the interface structurecontains either PBJA or PAJB. If the signature field of the interfacestructure does not contain either PBJA or PAJB then the interfacestructure has not been replaced and replacement must be performed.Accordingly if replacement must be performed step 396 is followed bystep 397. Otherwise step 396 is followed by step 399.

In Step 397 the PAJB jacket function performs interface structurereplacement by replacing the interface structure for the interfacepointed to by the interface object pointer parameter with a replacementinterface structure as shown in FIG. 32 and having a signature fieldvalue equal to “PAJB”. The signature is determined to be PAJB becausethe pointer to the interface object was returned (output) from theArchitecture A execution engine.

Thus it is seen that where a PAJB jacket function is invoked by a callfrom code executing under an Architecture A execution engine, or wherethe PBJA jacket function is invoked by a call from code executing underan Architecture B execution engine, no general function jacketing stepsas described in connection with step 326 of FIG. 31 are performed. Inthis way the present invention provides for efficient execution oforiginal interface functions without unnecessary general functionjacketing when an interface function is invoked by code executing on anexecution engine for which the interface was designed and developed.

LOAD TIME SUPPORT FOR INTERCEPTION OF FUNCTIONS

Referring now to FIG. 38, an example of a system 400 for load timeprocessing to support interception of predetermined service architecturefunctions or standard interface functions known to take a pointer to anobject is shown. The system includes a loader 405 having inputs of aload address 400 a, a predetermined function set 401, an address of ajacketing routine 402, and a code image to be loaded 403. The loadaddress 400 a is a location in memory where the code image is to beloaded. The function set 401 is a list of functions which take aninterface object pointer as a parameter. The list 401 may be in symbolicor binary address form. The jacketing routine address 402 is for examplean address of the program code implementing the jacketing routine 48 asshown in FIG. 3. The code image 403 is for example a non-native codeimage developed for an Architecture B, and including an import table404. The import table 404 includes a list of functions or routines whichare invoked from the image 403, but which are not implemented within theimage 403.

During operation of the elements shown in FIG. 38, the loader 405creates a loaded image 406 beginning at the load address 405 in memory.The loader 405 replaces the call address of all calls to functionscontained within the function set 401 with a pointer 407 to thereplacement code 408. The call addresses of functions contained in thefunction set 401 are for example contained within the import table 404.

The replacement code 408 invokes a Native_Call routine which isdeveloped to execute under the Architecture B execution engine, andwhich passes control to an Architecture A execution engine. TheNative_Call routine further retrieves the Jacketing_Routine_Address 410(from input jacketing routine address 402) and invokes the jacketingroutine to execute on the Architecture A execution engine. Thus theloaded image 406 is provided by the loader 405 such that each call to afunction within the function set 401 is replaced with a call toNative_Call, which in turn invokes the jacketing routine.

FIG. 39 shows an example of steps performed at run time to supportinterception of functions known to take a pointer to an object. At step411, a loaded image, such as for example shown as element 406 in FIG.38, reaches a point in it execution where a call had originally beenplaced to a function taking a pointer to an object. Since the image isan Architecture B image, it is executing on an Architecture B executionengine at step 411. As a result of the activity of the loader 405 inFIG. 38, the original call was replaced at load time with a call toNative_Call, followed by the Jacketing_Routine_Address as shown inreplacement code 408 in FIG. 38.

At step 412 the Native_Call routine is called and executed on theArchitecture B execution engine. The Native_Call routine gets theJacketing_Routine_Address, and invokes the jacketing routine to run onthe Architecture A execution engine. In an example embodiment whereArchitecture A is implemented in the underlying hardware, the jacketingroutine is developed in native code, and accordingly executesadvantageously fast on the hardware implemented Architecture A executionengine. At step 413 the jacketing routine executes, for exampleperforming the steps described in relation to FIG. 31. At the end of thejacketing routine in step 413, a Native_Return routine is called, whichreturns control to the Architecture B execution engine at the returnaddress following the Jacketing_Routine_Address in the loaded image. Atstep 414 execution thus resumes on the Architecture B execution engineat the return address in the loaded image.

GENERAL FUNCTION JACKETTING

FIG. 40 shows the steps performed to accomplish general functionjacketing. At step 415 argument conversion is performed. The argumentsto the original function are converted and/or reordered to compensatefor differences between the calling and argument conventions of theprocessor architecture of the execution engine from which the objectfunction is being called and the architecture for which the originalobject function was designed. Call back addresses are also modified asnecessary.

For example where the caller is executing on an Architecture A executionengine, and the called function is developed for Architecture B, andwhere Architecture A is the Alpha architecture, and Architecture B is anX86 architecture, the caller has placed the arguments into argumentregisters as is required by the ALPHA architecture. However, the X86architecture requires arguments to be passed on the stack. Thereforeduring 415 in this case the arguments are moved from the registers ofthe Architecture A execution engine onto the Architecture B executionengine stack for processing by the Architecture B execution engine.

Similarly, in an example implementation where Architecture A usesdifferent floating point representation or length than Architecture B,then floating point arguments are converted into the representation forArchitecture B in step 415. Other example functionality for step 415includes byte swapping where there is a different byte ordering requiredby Architecture A with respect to Architecture B.

At step 416 the original function is called on the execution engine forwhich it was developed. For example where the original function wasdeveloped for Architecture B, and is called from Architecture A'sexecution engine, at step 416 the address of the original function ispassed to the Architecture B execution engine. Control is passed to theArchitecture B execution engine at step 416 to execute the originalfunction.

At step 417 result conversion is performed. The jacketing routineaccommodates differences in return argument or result conventionsbetween the calling architecture and the architecture on which theoriginal object function was executed.

CONSIDERATIONS FOR BINARY TRANSLATION

The background optimizer 58 performs optimizations using a binary imageas input. Generally, the optimizations reduce execution time and reducesystem resource requirements. Optimizations are typically classifiedinto the following four levels: peephole optimizations, basic blockoptimizations, procedural or global optimizations, and interproceduraloptimizations. The number of assumptions regarding program structuregenerally increases with each level of optimization, peepholeoptimization assuming the least and interprocedural optimizationsassuming the most regarding program structure.

A peephole optimization uses a window of several instructions and triesto substitute a more optimal sequence of equivalent instructions. Abasic block optimization is performed within a basic block ofinstructions. Generally, a basic block is a group of instructions inwhich the first instruction is an entry point to the basic block, thelast instruction is an exit point of the basic block with a guaranteethat no instruction between the first and last instructions is itself acontrol transfer. A procedural or global optimization is performed upona group of instructions forming a procedure or routine. Aninterprocedural optimization is performed amongst or between procedures.

Existing methods of performing procedural and interproceduraloptimizations, as those typically implemented in an optimizing compiler,generally make underlying assumptions about the structure and propertiesof the code being optimized. For example, a method for a proceduraloptimization assumes that a called routine is entered via a callinstruction. The code corresponding to the called routine is executedvia a routine call made from another routine to the called routine usinga standard routine linkage, as typically defined in a calling standard.As part of the standard routine linkage, the called routine includes abeginning sequence of prologue instructions executed prior to the codecomprising the routine body.

Difficulties arise when performing procedural and interproceduraloptimizations on a binary image, because traditional assumptions cannotbe made about its structure. Such assumptions are made by existingsource code optimizers because they typically process only structuredinput having predetermined properties, such as a “filtered” intermediaterepresentation of a program produced by a compiler of a high-levellanguage. Usually, the intermediate representation includes well-definedstructures, such as a routine, and the compiler's optimizer makesassumptions regarding properties and structure about the input. When theinput is a binary image, such structural assumptions cannot be madebecause of the possible intermixing of machine instructions (code) anddata.

As a result, a new set of problems evolves when implementing proceduraland interprocedural optimizations in the background optimizer 58 thatoptimizes a binary image since assumptions about its structural cannotbe made. Existing procedural and interprocedural optimization techniquestypically implemented in an optimizing compiler cannot readily beemployed in the background optimizer 58 because properties and programstructure about the code included in the binary image input cannot beassumed.

Here in order to implement procedural and interprocedural optimizations,such as register allocation, local and global data flow optimizations,code motion and constant value propagation, in the background optimizer58 a basic unit of translation analogous to a routine using imageinformation available to the background optimizer is determined. Theimage information may include information comprising the binary imageitself, and information ascertainable from the binary image and itsexecution.

One problem is determining the general characteristics or parametersthat define the basic unit of translation. Another problem is, given abinary image, determining an efficient method to collect or obtainvalues for the parameters. The values are used to determine basic unitsof translation comprising the binary image upon which procedural andinterprocedural optimizations can be performed.

DETERMINING TRANSLATION UNITS

Referring now to FIG. 41, a portion of the translator 54 and optimizer58 included in the background system 34 that determines and usestranslation units from a binary image input is shown, e.g., thetranslation unit determiner 500 is shown. The translation unitdeterminer derives a unit of translation that is similar to thetraditional notion of a routine. At step 501 a, execution or run-timeinformation is gathered by the run-time interpreter 44. Specifically,the run-time interpreter gathers execution information stored as profilestatistics 17 c while interpreting code. At step 501 b, the optimizer ortranslator forms a unit of translation by determining a portion of theexecuted code that is analogous to a routine using the profilestatistics 17 c. In turn, at step 501 c, the optimizer or translator canperform traditional procedural and interprocedural optimizations, suchas register allocation, upon the portion of non-native executed codethat is analogous to a routine. The optimizations are performed duringthe translation of non-native code to native code by the backgroundsystem 34. A detailed definition of the unit of translation and themethod for forming the unit of translation is described in followingparagraphs.

The steps of FIG. 41 can be performed by a translator, an optimizer, ora combined unit performing the functional steps typically employed byboth an optimizer and a translator depending on the particularimplementation of the binary translation system. As will be discussed inthe ordering of the steps comprising translation and/or optimizationvary and affect whether the steps of FIG. 41 are performed by atranslator, an optimizer, or a combined unit.

Profile statistics, as mentioned above include execution informationabout a non-native image executed in the run-time system 32. Typically,profile statistics are stored by and associated with each binary image.The run-time system 32 notifies the server 36 as to the location of theprofile statistics 17 b, for example in a particular file stored ondisk, so that the server communicates the profile statistics to thebackground optimizer 58 included in the background system 34.

The run-time interpreter classifies non-native machine instructionswhich are executed into two general classes based on execution flowcontrol. The first class of instructions is a straight-line executionclass and includes instructions that do not alter the flow of executioncontrol. Upon executing a first instruction stored at a first memoryaddress belonging to the first class, the next instruction executed isstored at a second memory address contiguously following the firstinstructions. An example is an ‘add’ instruction or an instruction whichloads a register with the contents stored at a memory address.

The second class of instructions is a flow-alteration class and includesinstructions that, either conditionally or unconditionally, alter theflow of execution control. Typical machine instructions included in thesecond class are conditional and unconditional branch instructions, andjump instructions. The interpreter gathers run-time information aboutinstructions comprising the second class. The run-time information isstored as profile statistics in disk segment 17 c by the run-timeinterpreter.

An assumed property of a routine is that the code corresponding to theroutine is entered via a routine call. One method of forming a unit oftranslation analogous to a routine uses a target address to whichcontrol is transferred upon execution of a routine CALL. The profileexecution statistics gathered by the run-time interpreter include thetarget address to which control is transferred by a routine CALL, forexample, from another code section.

Detecting a transfer of control that is a routine CALL generallyincludes detecting the occurrence of a particular instruction thattransfers control to another instruction and belongs to theflow-alteration class. A routine CALL is detected by the run-timesystem. As an example, a calling standard defines a routine CALL toinclude a series of three (3) machine instructions to load a registerwith a target address and subsequently transfer control to the targetaddress. The last machine instruction in the series of instructions isan indirect jump instruction, such as “JMP @R27”, belonging to theflow-alteration class. Instructions prior to the jump instruction load ageneral register, “R27”, with the target address. The jump instruction,“JMP @R27”, then uses the contents of the register to obtain the targetaddress. The jump is “indirect” in that the register “R27” is not thetarget address. Rather, the register is a pointer in that the registercontains the target address. The “JMP @R27” instruction is aflow-alteration instruction comprising the CALL and is detected by therun-time interpreter. The target address of the last machineinstruction, e.g., “JMP @R27”, is stored as an execution or run-timeprofile statistic 17 c.

The step of forming a translation unit 501 b (FIG. 41) in thetranslation unit determiner 500 operates over the binary image toprovide one or more translation units.

Referring now to FIG. 41A, the steps for forming a translation unit areshown. At step 503, determining a translation unit analogous to aroutine begins by using a target address of a routine CALL as a startingpoint or entry point. The CALL entry point is read from the profilestatistics 17 c previously recorded by the run-time interpreter. TheCALL entry point (also referred to as “entry point”) is analogous to aroutine entry point. A determination is made, as in step 504, as towhether there are any remaining CALL entry points. If there is aremaining CALL entry point, the execution control flow or flow path istraced, as in step 505. A flow path is a series of instructions that canbe executed by the CPU depending on the evaluation of various run-timeconditions affecting the evaluation. A flow path originates from theCALL entry point. The flow paths originating from the CALL entry pointare traced by examining machine instructions beginning with theinstruction located at the CALL starting point or entry point. When aninstruction transfers execution control to one or more target locationsdepending upon run-time conditions and values, the execution flow isalso traced for each of these target locations.

For all execution or flow paths originating from the entry point,bounded “regions” of code within the binary image associated with thecurrent translation unit are determined, as in step 506. A translationunit is formed for each CALL entry point, until, at step 504, it isdetermined that all entry points have been processed. Subsequently, atstep 507, translation units are merged, as needed, to form anothercombined translation unit.

A translation unit comprises one or more unique regions of code. Aregion is defined as sequence of one or more machine instructions storedat consecutive non-native memory addresses. There are no “holes” or“breaks” in the memory area occupied by the machine instructions or codecomprising a region. Parameters that characterize a region include, forexample, a starting and an ending address representing the boundaries ofthe code associated with a region. Regions, translation units, and theinterrelations between them will be discussed throughout in thefollowing text.

Referring now to FIG. 42, a method of performing flow path determinationof step 505 of FIG. 41A is disclosed. As in step 508, flow pathdetermination commences by obtaining an entry point address that is aCALL target address from the profile statistics 17 c. The currentinstruction located at the current address is examined, as in step 510,to determine if it transfers control to another address altering thecurrent straight-line execution. A determination is made as to whetherthe current instruction belongs to the first or second aforementionedclass of instructions.

If the current instruction belongs to the aforementioned second class ofinstructions and transfers control to another instruction therebyaltering the straight-line execution, the instruction is also referredto as a transfer instruction. The transfer instruction is classified, atstep 512, as either i) an indirect or computed transfer of control, orii) a direct or program-counter relative (PC-relative) transfer ofcontrol. As in step 514, the technique used for determining the possibletarget locations to which control is transferred depends upon theclassification of the transfer instruction.

An indirect transfer of control uses a dynamic run-time value todetermine, as in step 514, its target address or addresses. For example,a computed jump instruction, such as “JMP @R5”, uses a run-time valuestored in a register of the computer system. The target address isdetermined at run-time using the value stored in the register “R5” whenthe jump “JMP” instruction is executed. The possible targets aredetermined using dynamic run-time information which typically changeswith each execution of the jump instruction. Such dynamic information isincluded in the profile statistics 17 c and is recorded by the run-timeinterpreter to determine the possible target(s) of the jump instruction.A method for determining the possible target locations is discussed inmore detail in conjunction with FIG. 42A.

Using a direct or PC-relative transfer of control, the possible targetlocation or locations can be determined, as in step 514, using offsetsrelative to the current instruction. The offset is included in thebinary image and additional run-time information, such as with anindirect transfer of control, is not needed to determine the targetlocations. These targets are added to a cumulative work list of targetshaving flow paths to be traced. For example, a conditional branchinstruction branches to a first address if a condition is true. If thecondition is not true, the next consecutive instruction is executed. Thefirst address is calculated by adding a fixed offset to the currentprogram counter. The current program counter identifies a memory addressof the current instruction. An example of a fixed offset is a byteoffset encoded in the binary image at or near the current branchinstruction. Thus, all possible targets can be determined using thecurrent program counter (PC) and the offset included in the binaryimage. The possible target addresses in the foregoing example are thefirst address and the address of the next instruction consecutive to thecurrent branch instruction.

Each memory address to which control can be transferred is a targetaddress (also referred to as “target” or “transfer location”). If thereare multiple possible target or transfer locations, each execution pathassociated with each target is traced one at a time. As in step 516, thebackground optimizer 58 chooses one of the possible targets andcontinues tracing that branch of the flow path.

Consecutive instructions in each flow path are sequentially examineduntil it is determined, as in step 518, that the current instruction isthe last instruction in the current flow path, i.e., terminates thecurrent flow path.

A flow path terminates when one of several conditions is detected. Whena routine RETURN is detected, a flow path terminates. A routine RETURNis similar to a routine CALL in that it is typically dependent upon amachine instruction set defined for a particular computer systemarchitecture. For example, a routine RETURN includes a particularmachine instruction which terminates tracing of the current flow pathbranch.

A flow path also terminates, as in step 518, when there is insufficientrun-time execution information to enable tracing to continue. In thiscase, the current flow path terminates when the current instruction isan indirect transfer instruction having an indirect target for which norun-time information has been obtained. Steps 514 and 516 have just beenexecuted and resulted in no targets being determined and, therefore, notarget selected. For example, an instruction is classified as anindirect transfer of control which uses run-time information todetermine the possible target(s). Typically, the run-time interpreter 44records the various target addresses for the indirect transfer ofcontrol. However, if the instruction that accomplishes the indirecttransfer of control is not executed, the run-time interpreter 44 isunable to determine and record associated run-time information in theprofile statistics. The background optimizer terminates tracing thecurrent execution path because it has insufficient run-time information,i.e., a null target.

Upon determining in step 518 that the current flow path terminates,another flow path or branch flow path is selected, at step 520, forexample a branch flow path associated with another target determined atstep 514 is selected from the work list.

At step 521, a determination is made as to whether there are anyremaining instructions to be examined, i.e., whether all flow paths orbranches thereof have terminated. If there are no remaining instructionsdetermined in step 521, tracing flow paths for the current translationunit terminates. If at step 521 there are remaining instructions,another instruction is examined by advancing to the next instruction atstep 522.

Generally, the method of FIG. 42 determines all possible flow pathextensions or branches originating from a main flow path with thecurrently selected CALL entry point. Each branch of the flow pathassociated with each target of transfer of control within a translationunit is traced until the branch terminates.

Referring now to FIG. 42A, a detailed description of step 514 of FIG. 42is shown when a transfer instruction is classified as an indirecttransfer of control. For determining all possible targets, thebackground optimizer 58 uses run-time information stored as profilestatistics 17 c by the run-time interpreter. The profile statisticsinclude, for an indirect transfer instruction stored at a non-nativeaddress, all target addresses to which control is transferred via theindirect transfer instruction. In one implementation in which theprofile statistics 17 c are organized in a hash table, the non-nativeaddress of the transfer instruction is used to determine a hash keycorresponding to the record entry in the hash table containing thenon-native address and the associated target addresses.

At step 524, entries comprising the profile statistics 17 c are searchedto locate a record entry corresponding to a first non-native address ofa current instruction, for which targets are being determined at step514. The precise method of searching performed at step 524 is dependentupon the organization of the profile statistics 17 c. At step 526, it isdetermined whether a match for the first non-native address of thecurrent instruction is found in the profile statistics. If no match isfound, as in step 528, the trace of the current flow path terminates. Aspreviously described, this condition can occur if a flow path comprisingthe current instruction has not been executed at run-time. Therefore,the run-time interpreter is unable to gather run-time information aboutthe current instruction.

If a match is found, as in step 530, the background optimizer 58 readsthe target addresses and determines, as by adding the target addressesto a list, that the flow paths or branches associated with the targetaddresses need to be traced. Execution proceeds to step 516 in which atarget, if any, is selected for tracing its associated flow path.

Other organizations of the target addresses included in the profilestatistics 17 c are possible. Access and search methods, such asretrieval of target addresses for an associated indirect transfer ofcontrol, may vary with implementation and depend upon the organizationof the profile statistics 17 c.

Referring now to FIG. 43, two types of example entries in the profilestatistics 17 c used to determine translation units of a routine areshown. The first entry type is a TARGET ADDRESS TYPE ENTRY 532comprising a NON_NATIVE_TARGET_ADDRESS tag 536, a CALL_FLAG 538 and aCOUNT 540. Each entry of this type comprises a unique non-native address536 which is the target of a transfer of a control. In toto, a list ofthese entries is used to represent all the locations to which controlhas been transferred at run-time as recorded by the run-time interpreterin the profile statistics. Each entry is unique from every other entryof the list. The NON_NATIVE_TARGET_ADDRESS 536 functions as anidentification tag or search index when searching for an entry amongstthe profile statistics, as previously described, for example when theprofile statistics are organized in a hash table. The CALL_FLAG 538 is aboolean flag set to TRUE when the associated NON_NATIVE_TARGET_ADDRESShas been the target of a routine CALL. Otherwise, CALL_FLAG is FALSE.COUNT 540 is an integer representing the total number of times controlhas been transferred to the associated NON_NATIVE_TARGET_ADDRESS. Forexample, if an instruction set comprises four instructions that transfercontrol, COUNT represents the number of times the associatedNON_NATIVE_TARGET_ADDRESS has been the target address to which controlhas been transferred by the four instructions.

When determining the translation units comprising a binary image, thetranslation unit determiner 500 examines each entry of the listcomprising TARGET_ADDRESS_TYPE_ENTRIES. The background optimizer 58would determine the CALL entry points, as used in step 503 of FIG. 41and step 508 of FIG. 42, by examining the CALL_FLAG field 538. A CALLentry point is one whose CALL_FLAG is TRUE. The translation unitdeterminer 500 traces the execution or flow paths originating from eachCALL entry point using the method steps of FIG. 42.

The second entry type of FIG. 43 is an INDIRECT CONTROL TRANSFER TYPEENTRY 534 comprising aNON-NATIVE_ADDRESS_OF_INDIRECT_TRANSFER_INSTRUCTION tag 542,NUMNUNIQUE_TARGET_ADDRESSES 544 and a TARGET_ADDRESS_LIST 546. An entryof this type is made for each indirect transfer of control. TheNON_NATIVE_ADDRESS_OF_INDIRECT_TRANSFER_INSTRUCTION tag is the addressat which the indirect transfer of control instruction is located, and,as described previously with the NON_NATIVE_TARGET_ADDRESS 536, can beused to determine a corresponding entry in the profile statistics 17 c.NUM_UNIQUE_TARGET_ADDRESSES is an integer representing the number ofunique values which have been a target address for the associatedinstruction stored atNON_NATIVE_ADDRESS_OF_INDIRECT_TRANSFER_INSTRUCTION. TARGET_ADDRESS_LISTis a list of non-native addresses. Each entry in the TARGET_ADDRESS_LISTrepresents a unique run-time value corresponding to a target address ofthe associated instruction stored atNON_NATIVE_ADDRESS_OF_INDIRECT_TRANSFER_INSTRUCTION. For example, theindirect transfer instruction “JMP @R5” transfers control to the addressdesignated by the contents of a register “R5”. This instruction islocated at address “X” and is executed five (5) times wherein each ofthe five times transfers control to a different target address. Therun-time interpreter recorded 5 unique target address values to whichcontrol was transferred from this instruction. The INDIRECTCONTROL_TRANSFER_TYPE_ENTRY corresponding to this indirect transferinstruction is as follows:

Field Name Value: NON-NATIVE_ADDRESS_OF_(—) XINDIRECT_TRANSFER_INSTRUCTION NUM_UNIQUE_TARGET_ADDRESSES 5TARGET_ADDRESS_LIST Y₀ Y₁ Y₂ Y₃ Y₄, each Y_(n) representing a targetaddress

A list of INDIRECT CONTROL_TRANSFER_TYPE_ENTRIES represents indirecttransfer instructions and associated run-time target addresses. Animplementation including an indirect transfer list performs the methodsteps of FIG. 42A. The profile statistics are searched to determine ifthe NON_NATIVE_ADDRESS_OF_INDIRECT_TRANSFER_INSTRUCTION field of anentry, if any, corresponds to a first non-native address of aninstruction. As previously described, the search method and technique isdependent upon the organization of the profile statistics 17 c. Uponfinding a matching list entry, the optimizer 58 adds the associatedtarget addresses from TARGET_ADDRESS_LIST to a list of target addresseswhose associated execution paths need to be traced.

In addition to tracing the flow paths originating from a CALL entrypoint, regions comprising the translation unit are also determined. Aregion and its associated beginning and ending boundaries are determinedwhile tracing the flow of execution, as in performing the method stepsof FIG. 42.

Referring now to FIG. 44, steps for determining the regions comprising atranslation unit, as at step 506 of FIG. 41A, are shown. Generally, theregions are determined by tracing the execution flow of instructions asdescribed by performing the steps of FIG. 42, examining each of theinstructions, determining a relation of the current instruction to theprevious instruction, and recording information.

At step 549, the current instruction located at a CALL entry definingthe beginning of a translation unit is examined. A current region isinitialized at step 550 with a starting address of the currentinstruction. At step 551, the next instruction, as from the instructionsequence produced by executing the method of FIG. 42, is examined. Adetermination is made at step 552 as to whether this is the lastinstruction in the translation unit, i.e., all flow paths have beentraced. If there are more instructions, a determination is made, at step554, as to whether the current instruction is contiguous with respect tothe immediately preceding instruction examined.

If the current instruction is not contiguous, the address following theend of the previous instruction is recorded, as in step 556, as theending address of the current region. The ending address is the addressof the previous instruction plus an offset equal to the size of theprevious instruction. As in step 558, a new current region is definedwith the starting address corresponding to that of the currentinstruction.

A determination is made at step 560 as to whether the current address iswithin the boundaries of an existing region other than the currentregion. If so, the existing region and the current region are combinedto form a new combined current region, as in step 562, representing aregion combining the existing region with the previous current region.The starting and ending addresses of the new combined current region aredetermined by examining the address boundaries defined for the existingregion and the previous current region. The address boundaries of thenew combined current region generally define a region including theunion of instructions in the existing region and the previous currentregion. For example, the starting address of the new combined currentregion of step 562 is the smaller of starting addresses of the existingcurrent region and of the previous current region.

The next instruction is examined at step 564 and control proceeds to thetop of the loop formed by step 552. According to the method previouslydescribed for tracing the execution flow as in FIG. 42, the nextinstruction will be contiguous to the current instruction if step 510evaluates to “NO”, and the current instruction is not the lastinstruction in the current flow path. Otherwise, the next instructionwill not be contiguous with respect to the location of the currentinstruction.

Each instruction comprising a flow path originating from the CALL entrypoint of the current translation unit is examined until, at step 552, itis determined that all instructions in the current translation unit havebeen examined. Subsequently, at step 566, the regions are merged. Oneway in which regions are merged is by examining the starting and endingboundary addresses of each region. If, through examination of boundaryaddresses, two regions are contiguous, the two regions are then mergedto form a combined region. For example, if the ending boundary addressof a first region is the starting boundary address of a second region,the first and second regions are combined to form a third combinedregion with a starting address of the first region and an ending addressof the second region.

The stream of instructions examined in the method of FIG. 44 areproduced by executing the method steps of FIG. 42. The method steps ofFIGS. 42 and 44 are integrated and performed in an implementation of thetranslation unit determiner 500 in one of a variety of ways. Forexample, prior to performing step 521, the translation unit determinersubsequently performs steps 554, and conditionally, steps 556 and 558,of FIG. 44.

Depending upon the order in which the method steps of FIGS. 42 and 44are performed, the order in which instructions are examined may varywith implementation. Additionally, depending upon the ordering of theforegoing method steps in an implementation, modifications to theforegoing method steps may prove beneficial to the particularimplementation. For example, when performing the method steps of FIG.44, a particular implementation may find it beneficial to purposefullyorder the instructions examined, as by increasing address, andaccordingly make beneficial modifications to the method steps of FIG.44.

When recording an ending boundary address, as in step 556, there may bean existing boundary address as a consequence of step 562. An update toan existing boundary address should result in the larger of the new orexisting value. A region does not get smaller. Rather, a region grows asmore execution paths or branches are traced. Consider the followingexample below of a pseudo-code representation of machine instructions ina binary image to be translated from non-native machine instruction tonative machine instructions:

ENTRY_1: :

Z: BEQ R1, 10, X; IF R1 is 10 goto X

Y: :

X: RETURN

“ENTRY_1” is a CALL entry point at which flow path tracing commences, asin step 508 of FIG. 42, with “X”, “Y”, and “Z” being symbolic referencesto non-native addresses. “Z” is the address of a direct or PC-relativeconditional transfer instruction which transfers control to theinstruction at address “X” if the contents of “R1”, register 1, is 10.“Y” refers to the instruction contiguously located following instruction“Z”. The method steps of FIGS. 42 and 44 are integrated so that theregions are being determined while tracing the flow paths. Specificallysteps 554 through 562 of FIG. 43 are performed sequentially andimmediately prior to step 521 of FIG. 42. However, in the followingdescription only significant execution occurrences of steps 554-562 willbe mentioned. Occurrences of “:” in the example pseudo-code aboverepresent an instruction that neither transfers control nor terminatesthe current flow path.

The instruction at address “ENTRY_1” is examined causing steps 510 and518 to evaluate to “NO”. A new current region, “REGION_1”, is definedwith the starting address “ENTRY_1”, as in step 550 of FIG. 44. Afterstep 522, the current instruction becomes the “BEQ” instruction locatedat address “Z”. The current region is “REGION_1” for which no endingaddress has yet been determined. A determination is made at step 510that “BEQ” is a transfer instruction. Step 512 classifies “BEQ” as aPC-relative transfer instruction. In determining the possible targetsfor step 514, no run-time information is needed from the profilestatistics 17 c. Two possible targets are determined as “X” and “Y”. Atstep 516, the background optimizer selects “X” as the target whose flowpath is currently being traced.

Step 518 determines that the current instruction, the transferinstruction located at “Z”, does not terminate the current flow path.Step 521 determines that there are more instructions in the current flowpath and the current instruction is updated, at step 522, to theinstruction located at “X”.

With the instruction located at address “X”, step 510 evaluates to“YES”. However, processing done by steps 512, 514, and 516 are moot when518 evaluates to “YES”. Step 520 results in the current flow path beingterminated. Step 520 selects the remaining flow path with the targetaddress “Y”.

Step 554 determines “X” is not contiguously located in memory withrespect to “Z”. “REGION_1” ends, at step 556, following the previousinstruction located at address Z. A new current region, “REGION_2”, isdefined with the starting address of “X”, the current instruction.

Step 521 evaluates to “YES” and the current instruction is updated, instep 522, to the instruction located at address “Y”. Steps 510 and 518evaluate to “NO”. Step 554 evaluates to “NO” since “Y” is notcontiguously located in memory with respect to “X”. Step 556 causes“REGION-2” to have an ending address following the instruction at “X”.Another region, “REGION_3”, is produced with a starting address of “Y”.

Step 521 evaluates to “YES” and step 522 updates the current instructionto be the “RETURN” instruction located at address “X”. Step 554evaluates to YES since “X” is contiguously located with respect to “Y”.Step 560 evaluates to “YES” since the current instruction's address, “X”is within the boundaries of another region, “REGION_2”. Step 562 causes“REGION_2” and “REGION_3” to merge and become a combined region, anupdated “REGION_2” with a starting address of “Y” and an ending addressfollowing the instruction located at address “X”.

Continued processing results, at step 566, in regions “REGION_1” and“REGION_3” being further combined into a single region beginning at“ENTRY_1” and having an ending address following the instruction locatedat address “X”.

Upon completing the formation of two or more translation units for abinary image, translation units are merged, as in step 507 of FIG. 41A.A translation unit comprises one or more unique regions. No regionbelongs to more than one translation unit. Therefore, when forming atranslation unit and determining its boundaries, if two translationunits have a common region, the two translation units are merged andconsidered a single translation unit. A “FORTRAN” routine havingmultiple entry points is an example of when two translation units aremerged.

The foregoing technique for forming translation units of a binary imageaffords a new and flexible way to determine a translation unit analogousto a routine enabling components of the background system 34, such asthe background optimizer 58, to perform procedural and interproceduraloptimizations in binary image translations. The methods of forming thetranslation units, as previously described, and binary imageoptimizations are performed in the background system which is furthercharacterized in the following text. Therefore, translation unitformation and optimizations, which are typically computer resourceintensive, are accomplished without adversely impacting the performanceof a computer system.

Typically, components of the background system 34, such as thebackground optimizer 58, employ techniques, such as optimizations, thatare expensive in terms of computer resources, such as CPU or systemmemory usage, to produce optimized translated native code. Components ofthe run-time system 32 cannot usually afford to employ such methods thatare expensive because the run-time system is constrained to perform itsactivities such that system performance is not impacted, such as duringa peak or heavy computer system usage time.

A component of the background system can perform tasks during non-peakusage computer usage times when there is usually less contention withother system tasks for computer resources. Additionally, since thebackground system does not typically involve user interaction, it is notnecessary to employ methods that emphasize performing optimizations andtranslations quickly. It is generally more important for the resultingnative translation to perform better at run-time than for a methodemployed by the background system to produce a resulting nativetranslation quickly.

The foregoing methods described are flexible in that they can be usedwhen performing a binary translation without placing restrictions andmaking undue assumptions regarding a binary image being translated. Thisflexibility allows the foregoing technique to be applied to generally toall binary images rather than restricting application of the foregoingtranslation unit determination technique for use with a small subset ofbinary images, such as those binary images satisfying a particular setof conditions or properties.

SAMPLE IMPLEMENTATION

Included below is C++-style pseudo-code representation of how aparticular implementation integrates the previously described steps fordetermining a translation unit, as previously described. See Appendix Afor an illustrative example. Following is an overview describing what iscontained in the Appendix A example

The example in appendix A includes pseudo code describing the foregoingtechnique for generating a set of Translation Units given an ExecutionProfile (Profile statistics). The set of Translation Units returned hasthe property that every location which is recorded as a call target inone of the execution profiles is also an entry point of exactly one ofthe Translation Units. In addition, any location in the binary image iscovered by at most one Region in one Translation Unit. The method worksby following the control flow of the binary image starting with thelocations which were the targets of calls in an execution of the binaryimage. (This information in recorded in the Execution Profile.)

The main loop of the method is in the routine find_translation_units.The routine build_translation_unit follows the control flow startingfrom a called location which is one of its parameters.Build_translation_unit follows the control flow using a work list tokeep track of locations which are the targets of control transfers thatremain to be explored. The actual parsing of source instructions inperformed in the routine visit_region. The method used bybuild_translation_unit is basically a standard graph walk.

Build_translation_unit provides a database of regions built up whilefollowing the control flow. The interface to this database is describedby the class Region_Db. The set of region in this database have theproperty that together they cover all the locations for which thecontrol flow has been followed and no two of the regions cover the samelocation. No location which has not been found to be reachable from aTranslation Unit entry is covered by a region in the region database.

As the control flow for a given call target is explored, it may bedetermined that a region is reachable from the entries of two differenttranslation units. In this case the translation units are merged tomaintain the property that no location is covered by the regions of morethan one translation unit. Whenever two adjacent regions are found tobelong to the same translation unit, they are merged to preserve theproperty that all the regions of a translation unit of as big aspossible.

INTERMEDIATE REPRESENTATION

During translation, the background translator reads instructions in thefirst instruction set comprising a translation unit from the binaryimage, builds an intermediate representation (IR) semanticallyequivalent to the instructions, and then modifies the IR to produce afinal version of the IR that corresponds to instructions in the secondinstruction set. In the example that will now be described, the firstinstruction set is associated with a complex instruction set computer orCISC. The second or resulting instruction set is associated with areduced instruction set computer (RISC).

Translating CISC instructions to RISC instructions typically includes“breaking down” one CISC instruction into one or more corresponding RISCinstructions. Thus, for a given CISC instruction, the IR generallyincludes one or more units of the IR which correspond to the“broken-down” CISC instruction.

One implementation of the IR uses a code cell as a basic atomic unit forrepresenting instructions in the IR. The IR comprises one or more codecells connected, such as in a linked list representation. The IR issemantically equivalent to the CISC instructions input to the backgroundtranslator.

Referring now to FIG. 45 a list of code cells 600 include one or morecode cells 602 a-c. Typically, each code cell is a data structure hasone or more fields. Code cell 602 includes an opcode field 604corresponding to an operation upon one or more operands 606. The fieldswithin a code cell and their uses may vary with implementation and thefirst and second instruction sets.

In one implementation of the IR, the IR opcodes of the binary translatorare a union of both the instructions from a first non-native instructionset or source instruction set and a second native instruction set ortarget instuction set. The code cells can include some pseudocodeinstructions which are instructions that are neither in the source northe target instruction set. Rather, a pseudocode instruction is includedin the IR representation to annotate the IR or support an intermediatestate of the IR transformed from source to target instructions.

Initially, the IR typically includes instructions in the source ornon-native instruction set. At the end of the binary translation, the IRtypically only comprises code cells of target or native instructions. Inthe process of performing the binary translation, the IR is transformedfrom its initial form comprising only source instructions to its finalform comprising target instructions. During the binary translation theIR itself may comprise any combination of source, target or destination,and pseudocode instructions.

There are many ways in which the background system 34 in the embodimentof the code transformer 800 (FIGS. 58A to 71C) intermixes the steps oftranslation and optimization. As a result, the IR upon which anoptimization may be performed can comprise any combination of source,target, and pseudocode instructions. Therefore, an optimizationtechnique, such as data flow analysis, used in binary translation shouldbe flexible enough to handle any form of the IR.

As a result of intermixing translation and optimization, constraintssuch as amount of available memory will vary depending on when theoptimizations are performed. A technique used in performingoptimizations should be flexible enough to trade-off optimizationexecution time for storage space or memory as needed during thetranslation and optimization steps. For example, at one point globaldata flow information may be needed to perform an optimization, butlocal data flow information is not needed. The technique for performingthe optimization should not incur additional overhead associated withthe local data flow analysis, such as storage of the local data flowinformation, when only global data flow information is needed.

The background optimizer 58 processes the list of code cells 600 toperform optimizations using a binary image as input. Generally,optimizations reduce execution time and reduce system resourcerequirements of a machine executable program.

DATA FLOW ANALYSIS

One process typically performed as part of optimization processing isdata flow analysis in which information is gathered about data values ordata definitions. Data flow analysis generally refers to examining aflow graph or flow of control within a routine and collectinginformation about what can be true at various points in the routine.

Prior to performing data flow analysis, control flow analysis istypically performed which includes identifying one or more basic blockscomprising a routine, as mentioned above. Data flow analysis, astypically performed by an optimizing compiler, is a two level processincluding local and global data flow analysis information. Local dataflow analysis produces information about what is true within a basicblock, such as the data dependencies within a basic block. Global dataflow analysis produces information about what is true between or amongstbasic blocks, such as the data definition dependencies between basicblocks.

EXAMPLE

Referring now to FIG. 47 and FIG. 48, a data structure 601 which is aninstantiation of the IR 600 during translation of the non-native imageis shown. The data structure 601 represents local data flow analysisinformation for the IR code cells as shown in 601 a. The statementsbelow correspond to opcodes, operands and other data as may be presentin the code cells 601 a. The digits in the left hand corner are forreferencing the code cell in text which follows.

1. add 1, ax, ax

2. ld [mem1], bx

3. add 8, ax, mem1

4. cmp ax, bx

The IR 601 is an intermediate version of an initial IR furthertransformed into a final IR as will be described below in conjunctionwith FIGS. 58A to 71C.

As shown above, the first statement (1) which corresponds to the firstcode cell adds the constant “1” to the contents of register “ax” andplaces the result in register “ax”. The second statement (2),corresponding to the second code cell, loads the contents from memorylocation whose address is in register “mem1” into register “bx”. Thethird statement (3), corresponding to the third code cell, adds theconstant “8” to the contents of register “ax” placing the results inregister “mem1” indicating an address in main memory. The fourthstatement (4), corresponding to the fourth code cell, compares thecontents of register “ax” to the contents of register “bx”.

The foregoing four (4) statements are depicted as IR code cells 601 a inthe data structure 601. A basic block comprises four (4) code cells 618a-618 d which respectively correspond to the four (4) IR code cellsabove. In this example, the data structure 601 includes, in addition tothe IR code cell data structures 601 a, a basic block (BB) datastructure 609, basic block value (BBV) data structures 640 a-640 f,basic block state cotaines (BBSC) data structures 628 a to 628 d andstate container (SC) data structures 630 a-d. The basic block value(BBV) 640 a, BB basic block (BB) 609, and basic block stat containers(BBSC) 628 will now be described in more detail.

BASIC BLOCK VALUE DATA STRUCTURE

The BBV, such as 640 a, is a data structure included in the IR andabstractly represents a data value, its definition (if any) and anyreferences to that data value by instructions within the basic block. ABBV such as 640 a comprises six fields, a read_list_head (READ_LST) 656,a definition (DEF) 657, a BBSC pointer (BBSC) 658, a modify-writeboolean (MOD. WRITE) 659, as well as two other fields, a read-modifypointer (RD. MOD. PTR) 660 and a pointer to the next BBV (BBV NEXT) 662.The read_list_head 656 is a pointer to the first operand which does aread of the data value associated with a BBV. The definition field 657is a pointer to the operand which does a write or defines a data value.The BBSC pointer 658 points to a BBSC that is associated with a statecontainer. All BBVs associated with a particular state container withina given basic block are “threaded” on a linked list with its list headin the corresponding BBSC. That is, all BBVs associated with theparticular state container are connected in a linked list where then^(th) element of the list points to the n^(th+1) element of the list.This connection is established by the BBV next field 662 which points tothe next consecutive BBV associated with a state container. Theremaining two fields, modify-write boolean 659 and read-modify pointer600, will be discussed in following text in conjunction with otherfigures.

BASIC BLOCK STATE CONTAINER DATA STRUCTURE

A BBSC data structure such as 628 a comprises seven (7) fields: a USELIST head (USE LIST HEAD) field 664, a DEF LIST head (DEF LIST HEAD)field 666, an SC pointer (SC POINTER) 668, a BBV list head field (BBVLIST HEAD) 670, a BB pointer (BB POINTER) 671, a BBSC summaryinformation (BBSC SUM INFO) 672 and a pointer to the next BBSC (BBSCNEXT) 673. The USE LIST head 664, DEF LIST head 666 and BBSC summaryinformation 672, and are discussed later in conjunction with global dataflow analysis. The SC pointer field 668 contains a pointer from the BBSCto the state container (SC) associated with the data values. The BBVlist head field 670 contains a pointer to the first BBV associated witha state container. A BB pointer 671 contains a pointer from the BBSC tothe basic block data structure or BB data structure with which this BBSCis associated. Finally, the BBSC next field 673 contains a pointer tothe next BBSC associated with the basic block designated by field 671.

BASIC BLOCK DATA STRUCTURE

Five (5) data fields comprise the basic block (BB) data structure 609are also shown to include the Inst_forward (INST_FOWARD) field 674,Inst_backward (INST_BACKWARD) field 675 and BBSC head pointer (BBSCHEAD) field 676, as well as In_CFE_list (IN_CFE_LIST) 678 andOut_CFE_list (OUT_CFE_LIST) 679. The In_CFE_list is a pointer to thehead of the list of control flow edges or CFEs into a basic block 609.The Out CFE_list is a pointer to the head of a list of control flowedges out of a basic block 609. These two (2) fields and their uses willbe discussed in more detail with global data flow analysis. TheInst_forward field is connected via a pointer 610 to the first code cell618 a of the basic block. Pointer 610 and connecting pointers 612 a-612c enable a forward traversal of the linked list of code cells comprisingthe basic block 609. Similarly, the Inst_backward field is connected tocode cell 618 d, which is the last code cell in the list, by pointer614.

Use of pointer 614 combined with pointers 616 a-616 d enable a backwardtraversal of the linked list of code cells comprising the basic block.The third field BBSC head is connected 615 to a list of basic blockstate containers (BBSC) associated with the basic block.

CODE CELL DATA STRUCTURE

A code cell in this IR comprises an opcode field and multiple operandfields. For example, code cell 618 a comprises an opcode field 620 a andoperand fields 622 a, 624 a and 626 a. Similarly, each of code cells 618b-618 d each comprise an opcode field and three operand fields. Theopcode comprising the opcode field 620 can be represented either as atextual mnemonic or as a numeric value associated with a certaininstruction. An operand in this implementation can represent a literal,a register operand or a memory location. An operand such as 622 a whichis a literal is denoted in the diagram as a constant value stored withinthe operand field of the code cell. An operand can also correspond to amemory location or a register operand. In either of these cases, anoperand field of a code cell designates a register or memory operand bybeing associated with a basic block value (BBV) having a correspondingdata definition. For example, field 626 c is the third operand of codecell 618 c. The third operand is associated with a register used toidentify a main memory address through pointer 625c connecting field 626c with BBV2 for a register “mem1” 640 e.

USE OF BBV

There is one BBV per computed value for a given data value. If anotherdefinition within a basic block is given to, for example, register “ax”such as a destructive reassignment of a new value to register “ax”,there would be another BBV for register “ax” since there are twodistinct data values or definitions for the same register “ax”,Therefore, each BBV provides direct connectivity to all correspondingcode cells which define and reference the data value associated with theBBV.

An example of a data value having two data definitions is shown in FIGS.47 and 48. The second operand field 624 a of code cell 618 a referencesregister “ax”. Operand field 624 a is associated with BBV1 of register“ax” through pointer 623a which connects the operand field 624 a withBBV1 of register “ax” 640 a. The second operand field is reading a valuefrom register “ax” adding one (1) or incrementing it, and assigning theresult back into register “ax”. The third operand field 626 a writes theresult to register “ax” producing a new data value by this reassignmentof an incremented result to register “ax”. A second BBV of register “ax”640 b is associated with the third operand field 626 a of code cell 618a. This connection is denoted by pointer 625 a.

BBVs 640 a-640 f represent a general class of data values about stateinformation that may be referenced or modified by an IR instruction.State information includes for example, registers, condition codes, andmain memory locations. What comprises state information varies withimplementation and the first instruction set being translated to asecond instruction set.

STATE INFORMATION

Each piece of state information is denoted by a state container (SC) asdepicted by elements 630 a-630 d. Five pieces of state information areaffected by IR code cells 618 a-618 d. Specifically, these pieces ofstate information are: register “ax” 630 a, register “meml” 630 b,register “bx” 630 c, condition codes (not shown) and main memory 630 d.In the IR data structure 601 all of main memory 601 is treated as asingle piece of state information. For example, a modification (write)to any memory location is shown in the IR as a data interactionaffecting a subsequent use (read) of any memory location. Otherembodiments of the IR may divide main memory into multiple parts, eachpart being analogous to a different piece of state information. Notethat FIGS. 47 and 48B are a snapshot of the IR during binary translationprior to converting condition codes to state containers, as explainedabove. Each of the BBV_(S) 640 a through 640 f is connected to theappropriate state container to which the BBV refers through the basicblock state container (BBSC) data structures 628 a to 628 d. The BBSCdata structures 628 a to 628 d complete the direct global connectivitybetween code cells which define or use, e.g., read, or write, to thecorresponding state container in multiple basic blocks.

DATA FLOW (LDF) INFORMATION

As shown in FIGS. 47 and 48, pointer 642 a establishes a connectionbetween BBV1 of register “ax” 640 a and the first operand 624 a whichdoes a read of register “ax”. Pointer 642 a connects the read list headfield of BBVl of register “ax” 640 a to the second operand of code cell618 a. The next_op field of operand 624 a contains a pointer to the nextoperand which does a read of BBV1 of register “ax”. In this example,there is no next operand which does a read of the value associated withBBVl of “ax”, therefore, the next_op field of 624 a is null denoted by651 a* representing a null pointer, e.g., that this is the end of thelist. If there were more than one operand which did a read of this datavalue of register “ax”, pointer 651 a would designate the nextconsecutive operand rather than a null value. The Def (definition) fieldof BBV1 of register “ax” 640 a contains a null pointer 646 a. This isbecause the definition used by the first code cell is not defined withinthe basic block. Therefore, the definition for this BBV is denoted by anull pointer indicating that it is not defined within this basic block.The definition of the data value associated with BBVl for register orstate container “ax” exists in another basic block and is a global datavalue. This is discussed in the following text in conjunction withglobal data values. Within the basic block there is no local definitionprovided for the state container. An example of a local data definitionis pointer 646 b of BBV2 of register “ax” 640 b. Pointer 646 b connectsthe Def field of 640 b to the third operand 626 a of code cell 618 a.The BBSC field of BBV1 of register “ax” 640 a points to BBSC of register“ax” 628 a of FIG. 47 as denoted by pointer 648 a. The first BBV of “ax”640 a is connected to the second BBV for register “ax” 640 b by pointer650 a.

FIGS. 47 and 48 illustrate by example the connections established by thementioned BBSC data structure fields. The BBSC of register “ax” 628comprises the four (4) fields BB pointer 671, SC pointer 668, BBV listhead 670 and BBSC next 673. Pointer 632 a designates a connectionbetween BBSC of “ax” 628 a and BB 609. Pointer 638 a establishes aconnection between the SC field of BBSC of “ax” 628 a and statecontainer “ax” 630 a. The BBV list head field has a pointer 634 a toBBV1 of “ax” 640 a. Remaining BBVs associated with the state container“ax” are threaded on a linked list headed by the BBSC. For example, BBV1for register “ax” 640 a is connected to the second BBV for register “ax”640 b by pointer 650 a connecting the BBV next field of 640 a to BBV2 ofregister “ax” 640 b. Pointer 636 a connects the BBSC for register “ax”with the next BBSC 628 b for state container “mem1”. All of the BBSCsassociated with the basic block are also connected on a threaded linklist wherein the next field of BBSCnpoints to BBSC_(n+1).

IR OPCODE TABLE

Referring now to FIG. 49, an IR opcode table 680 is depicted ascomprising various opcodes and associated information. An implementationcan store the various opcodes used in code cell fields 620 a-620 d in anIR opcode table. Table 680 as shown has five (5) columns of information.Opcode column 682 is a list of all of the opcodes used within the IR.Specifically, the opcodes 682 a and 682 b can appear in the opcode fieldof an IR code cell. In one implementation, the opcodes are representedas ASCII text which map ASCII text appearing in the opcode field of acode cell in the IR. If an implementation represented an opcodeappearing in the opcode field of an IR code cell as a numeric value orinteger quantity, this table may contain an additional columnassociating the numeric value or opcode number with an IR opcodeinstruction mnemonic comprising ASCII text. Column 683, the operandcount, contains an integer quantity that represents the number ofoperands for the associated opcode appearing on the same line in column682. The IR opcode table 680 comprises three operand fields 684-686,respectively. The operand count field will designate how many of thesucceeding operand columns 684-686 contain valid operand informationassociated with the corresponding opcode. Each of the operand fields684-686 contain information about the type of access that operandperforms on a state container or data value. For example, opcode 682 ais an ADD instruction with three (3) operands. The first operand 684 areads a data value associated with a state container. Similarly, thesecond operand 685 a also reads a data value associated with a statecontainer. However, the third operand 686 a performs a write andactually provides a data definition for a data value associated with astate container.

Opcode 682 b is an increment (INC) opcode having one (1) operand asdesignated by the operand count 683 b. The operand count of one (1)associated with the increment instruction 682 b means that operandfields 685 b and 686 b contain no information relevant to the opcode.Operand 1 has read-modify write access 684 b to a data value. In thisexample, read-modify write means that the increment instruction, eventhough it has one (1) operand, reads the data value associated with theoperand, modifies the data value by incrementing it, and then writes theupdated data value back to the state container. This is one example withonly one operand where both a read and a write is performed to a statecontainer. This increment instruction also exemplifies a case in which afirst data value associated with one BBV is read and a data definitionassociated with a different second BBV is also provided with a singleoperand single instruction.

Referring now to FIG. 50, an example use of the increment instruction orINC instruction is shown. FIG. 50 depicts an example using two fields ofthe BBV not previously described. These fields are the modify-writeboolean 659 and read-modify pointer 660 of BBV 640. For the sake ofclarity, FIG. 50 contains only those pointers relevant to highlightingthe use of these two (2) BBV fields in conjunction with the code cellsand BBSCS. In particular, these two (2) BBV fields are used inconjunction with IR opcodes such as the increment instruction 682 b ofFIG. 49 which has a read-modify write operand performing both a read anda destructive write operation to the same state container. Thus, anoperand of the increment opcode will refer to two BBVs for the samestate container.

In FIG. 50, code cell 618 h is an increment (INC) instruction. Code cell618 h increments the contents of register “ax” and then rewrites thatvalue to the state container register “ax”. To represent this local dataflow information using the BBV, BBSC and code cell data structures,pointer 693 connects the read-modify field of BBVl of register “ax” 640f with the first operand of code cell 618 h. The first operand of theincrement instruction also performs a write to the state containerregister “ax” by incrementing the value of the contents of register“ax”. This produces a second data value for register “ax”. FIG. 50contains a second BBV of register “ax” 640 g. The definition for thesecond data value is indicated by pointer 694 which connects the DEF(definition) field of BBV2 of register “ax” 640 g to the first operandof the increment codecell 618 h. The second BBV for register “ax” hasthe field modify-write set to TRUE. Modify-write is a boolean valuewhich is true when the definition associated for that data value is theresult of a read-modify write as in this case with the incrementinstruction of code cell 618 h. Otherwise, modify-write is FALSE.Overall FIG. 50 contains four (4) code cells 618 f-618 i. FIG. 50highlights the use of two (2) fields of the BBV, the read-modify fieldand the modify-write field, used to indicate data flow analysisinformation regarding a read-modify operand and the two associated BBVsfor the modify state container. Note that for efficient memory use, animplementation may choose not to allocate unused operand fields, asshown in the last two operand fields of codecell 618 h of FIG. 50.

The foregoing data structures and figures illustrate a representation oflocal data flow analysis information which is efficient and providesdirect connectivity to those instructions or code cells which performreads and writes to a state container. Data structures as those picturedin FIG. 47 and FIG. 48 and FIG. 50 are built by traversing a list ofcode cells off of a basic block. For example, referring again to FIG. 47and FIG. 48, the list of code cells is traversed beginning with thefirst code cell pointed to by pointer 610 of BB 609. For a given opcodesuch as the ADD opcode of code cell 618 a, the IR opcode table 680 canbe used to obtain information regarding the type of access of itsoperand and the number of operands for the given opcode. Using thisinformation, the BBVs and the BBSCs can be built by traversing the listof code cells and establishing necessary connections between operands,for example, and BBVs.

REPRESENTATION OF GLOBAL DATA FLOW INFORMATION

One technique for representing global data flow information isinterconnected with the local information just described. Recall thatthe global data flow information includes upwardly exposed uses, ordependencies within a basic block in which the data item is given avalue in another basic block. With respect to the basic block whichreferences an upwardly defined data item, these references are alsocalled global references. Global data flow information also includesdata definitions within a basic block that are referenced in othersubsequent basic blocks. With respect to the basic block which definesthe data item globally referenced by other basic blocks, thesedefinitions are referred to as global definitions comprising global dataflow information.

One technique for performing global data flow analysis uses local dataflow analysis information recorded in a BBSC summary information field672 of FIG. 47. The BBSC summary information field describes how a basicblock accesses an associated state container. In other words, the BBSCsummary information describes how BBVs within a basic block manipulate astate container. Since a basic block is associated with one or moreBBSCs, all local data flow summary information about the basic blockused during global data flow (GDF) analysis can be easily obtained byexamining the the BBSCs associated with a basic block.

Referring now to FIG. 51, the BBSC summary information field 672previously seen in FIG. 47 will now be described. The BBSC summaryinformation field is a single value that represents one of five patternsof access performed within a basic block of the associated statecontainer. FIG. 51 shows these five possible patterns. Read access 708indicates that only read accesses are performed within a basic block.Any access within this basic block reads a value which is upwardlyexposed or defined within another basic block.

A second pattern of access within a basic block to a state container iswrite access 710. If the first mention or use of the state containerwithin a basic block is a write, e.g., there is a write and no precedingreads of that state container, then the summary information willindicate that write access is performed defining a data value that maybe used in another basic block.

A third pattern of access to a state container within a basic block isread-write access 712. The read-write access value indicates that a readis performed within the basic block which is dependent upon an externaldefinition defined within another basic block. That is, when the firstmention of the state container within the basic block is a read,read-write access 712 will be set. Additionally, there is also a writeaccess within the basic block giving a newly assigned value to theassociated state container. The newly assigned value may be used inanother basic block.

A fourth pattern of access to a state container within a basic block isread-modify-write access 714. Recall in conjunction with the fields ofthe BBV we had a modify-write and read-modify field corresponding toinstructions such as the increment instructions which reads and modifiesthe state container within a single instruction. A read-modify writepattern of access for a basic block implies that all writes to theassociated state container are of the nature of the incrementinstruction, e.g., a read and write to the same state container with thesame instruction.

A fifth pattern of access within a basic block to a state container mayindicate no local access 716 implying that the associated statecontainer is not accessed, e.g., not actually read or written, withinthe basic block.

Referring now to FIG. 52, an arrangement of the data structuresrepresenting global data flow analysis information is depicted. Threebasic blocks BB0, BB1 and BB2 are respectively numbered 609 a-609 c. Asshown in FIG. 52, a basic block such as BB0 is associated with severalBBSCs. For presentation purposes in FIG. 52, this association isrepresented by enclosing the BBSCs in a bit vector form within a basicblock. For example, BB0 609 a is depicted as a rectangle enclosing oneor more BBSCs, such as BBSC1 628 f for register “bx”. For the sake ofclarity, FIG. 52 only depicts the BBSC summary information field 707a-707 c of the BBSC. As indicated in BBSC3 for register “bx”, BB2performs a read of register “bx”. This indicates that BB2 has anupwardly exposed read dependency which reads a definition supplied byanother basic block. Edges representing global data flow (GDF)connections are GDF1 718 a and GDF2 718 b each indicating a definitionfor state container ′bx” can originate from a write performed in BB0 orBB1. Examining BBSC1 628 f and BBSC2 628 g for register “bx”, BB0 andBB1 both perform a write access to state container “bx”. Pointer or GDF1edge 718 a represents the global data flow connection between BB0 andBB1 in that BB0 can supply a value for state container “bx” read withinBB2. Similarly, pointer GDF2 718 b represents the global data flowconnection between BB1 and BB2 in that BB1 can supply a value ordefinition for a value of state container “bx” read within BB2.

Control flow on the global level between basic blocks is denoted bycontrol flow edges CFE1-CFE3, respectively 720 a-720 c. A control flowedge is used to represent the possible execution control flow pathsbetween basic blocks. In FIG. 52, BB0 and BB1 flow into BB2.

DETAILS OF GLOBAL DATA FLOW (GDF) INFORMATION

FIG. 53 details the GDF information represented in FIG. 52 by pointersGDF1 and GDF2. FIG. 53 highlights the DEF list head field 722 and USElist head field 724 of the BBSC and shows how they are used inrepresenting global data flow analysis information. Recall from FIG. 52that BB2, which is associated with BBSC3, can receive a definition forstate container “bx” from either BB0 or BB1, as depicted by pointersGDF1 and GDF2 respectively. The relationship represented by GDF1 andGDF2 is detailed in FIG. 53 by having a DEF list head field of the BBSC628H for register “bx” connected 722 c to a first BBSC connector 725 b.The DEF list head pointer 722 c points to the beginning of a threadedlist of BBSC connectors 725 b-725 d in which the BBSCs provide adefinition for a state container read within the basic block associatedwith BBSC3 for register “bx”. BBSC connector 725 b points 726 a to BBSC1for register “bx” 628 f. Similarly, BBSC connector 725 c points 726 b toBBSC2 for register “bx” 628 g. Functionally, a first BBSC connectorassociated with a first basic block points to a list of all globaldefinitions used within the first basic block for a state containerdefined within another basic block. As indicated by null pointers 722 a*and 722 b*, BBSC1 and BBSC2 for register “bx” do not have any upwardlyexposed reads dependent on definitions for register bx defined withinanother basic block.

FIG. 53 also illustrates the USE list field 664 as previously mentionedin conjunction with FIG. 48. Functionally, the USE list field of a firstBBSC associated with a first basic block represents a list of externaldata references of other basic blocks which depend on a value definedwithin the first basic block. For example, BBSC3 628 h for register “bx”is associated with BB2 which reads register “bx” using a data valuedefined in either BB0 or BB1. The representation of the globaldefinition provided by BB0 uses BBSC1 628 f associated with BB0. The USElist field of BBSC1 for register “bx” points 724 a to a BBSC connector725 a which is connected 726 d to BBSC3 for register “bx”. Thedependency of BB2 upon a value written in BB1 is similarly represented.The USE list head field of BBSC2 628 g is associated with BB1 providinga second possible data value definition for register “bx” which can beread in BB2. The representation of this data value definition isindicated by pointers 724 b, BBSC connector 725 d, and pointer 726 c.Thus, FIG. 53 indicates the detailed connections of the global data flowconnections abstractly represented by GDF1 and GDF2, respectively, 718a-718 b, of FIG. 52.

CONTROL FLOW EDGE

FIG. 54 depicts a detailed view of a control flow edge (CFE).Specifically FIG. 54 is a more detailed description of CFE2 720 brepresenting the control flow edge between BB1 and BB2. FIG. 54 alsohighlights two basic block fields in In_CFE_list 730 and Out_CFE_list732 previously mentioned regarding the basic block data structure 609.In_CFE_list points to a list of CFE connectors 733 representing allincoming control flow edges to a basic block. Similarly, theOut_CFE_list 732 functionally represents all outgoing control flow edgesfrom a basic block. Connector 733 connects a source basic block 734 witha target basic block 736. If there are multiple source basic blocksflowing into the indicated target basic block, the source CFE next field738 points to another CFE connector 733. Similarly, if there aremultiple target basic blocks for a given source basic block indicated by734, the target CFE next field 739 would point to another CFE connector733 representing information about another target basic block.

The foregoing data structures comprising the global data flow analysisinformation are typically produced using a method which performs globaldata flow analysis of a program by performing global data flow analysisupon each routine that is included in the program.

METHOD OF PERFORMING GLOBAL DATA FLOW ANALYSIS

Referring now to FIG. 55, method steps for performing global data flowanalysis are described. The method steps of FIG. 55 are based on amethod described in “Efficiently Computing Static Single Assignment Formand the Control Dependence Graph”, ACM Transactions on ProgrammingLanguages and Systems, Vol. 13, No. 4, October 1991, Pages 451-490, byRon Cytron et al. These method steps are performed for each routinecomprising a program. Beginning in step 746, any global data flowconnections from a prior global data flow analysis are first eliminated.The “dominator tree” is computed as in step 748. A “dominator tree”represents a relationship between basic blocks. A first basic block of aroutine “dominates” a second basic block if every path from the initialbasic block when tracing the control flow of a program to the secondbasic block goes through the first basic block. Under this definition,every basic block “dominates” itself and the first basic block of aroutine may “dominate” all other basic blocks in the routine assumingthat there is only one common entry point to the routine. A useful wayof representing dominator information is in the tree called the“dominator tree” in which the initial basic block is the root of thetree and the tree has the property that each node represents a basicblock and “dominates” its descendants in the tree. A detailedrepresentation of a “dominator tree” is given in the referenceCompilers, Principles, Techniques and Tools by authors Aho, Sethi, andUllmann, and in the reference “Efficiently Computing Static SingleAssignment Form and the Control Dependence Graph” by Citrol et al.

After computing the “dominator tree”, the “dominance frontier” iscomputed as in step 750. The concept of a “dominance frontier” and amethod for computing the dominance frontier is also detailed in“Efficiently Computing Static Single Assignment Form and the ControlDependence Graph”, by Citron et al. X and Y are two nodes in a flowgraph of a routine. Each node X and Y are basic blocks in the instantcase. If X appears on every path from routine entry to Y, then X“dominates” Y, as previously discussed. If all paths to node Y muststrictly and only go through X to reach node Y, X “strictly dominates”Y. Generally, the “dominance frontier” of a node X in the flow graph isthe set of all nodes Y in the flow graph such that X “dominates” apredecessor of Y in the flow graph, but does not “strictly dominate” Y.A predecessor of a node Y is a node which precedes Y in the flow graph.

All local data flow (LDF) information is computed for all basic blocksof the routine as in step 752. Merge points for routine are thencalculated in step 754. Finally, global data flow connections (GDF) areformed as in step 756. The global data flow connections formed in step756 create the GDF edges or pointers as depicted in FIG. 52 and 53.

A merge point, as in step 754, is a merge or joining definition pointwithin a routine for multiple definitions of the same state container.Referring now to FIGS. 56A and 56B, detailed method steps 754 fordetermining merge points are shown. The method described in FIGS. 56Aand 56B makes a list of all of the definitions within a routine and thenadds merge point definitions using the dominance frontier.

A first state container (SC) for a routine is obtained as in step 758. Adetermination is made as in step 760 as to whether or not this is thelast SC associated with a routine. If it is the last SC, the methodstops as in step 762. If this is not the last SC, a boolean flag upwardexposure is initialized to null as in step 764. The list of BBSCsassociated with a state container is traversed beginning with a firstBBSC as in step 766. A determination is made as in step 768 as towhether or not there are any more BBSCs associated with the currentstate container. If a determination is made that this is not the lastBBSC associated with a state container using the BBSC summaryinformation the pattern of local access within the basic block isclassified as in step 770.

The access falls into one of four (4) classifications or patterns. Ifthere are read and write accesses or a read-modify-write access within abasic block, upward_exposure is set to “yes” as in step 771 and thedefinition of the data value created by the write is added to an ongoinglist of definitions. If there is only read access, upward_exposure isset to “yes” as in step 773.

If there is no local access at all, as in step 774, merge BBSCs remainfrom a previous global data flow computation. Therefore, these remainingBBSCs are deleted. Typically, as will be explained in following text,BBSCs are produced representing an artificial definition of a statecontainer to represent merging definitions in a routine. In step 774, ifa BBSC exists when there is no local access to a state container withinthe associated basic block, the BBSC was produced from a previousiteration of the method steps of FIGS. 56A and 56B for finding mergepoints. These BBSCs are deleted in step 774.

If the basic block local access is determined to be a write only access,that is, there are no reads but only a write access as in step 776, adefinition is added to a list of definitions being maintained. Controlthen proceeds to step 778 where the next BBSC is examined. Control thenreturns to step 768 for a determination again as to whether there areany more BBSCs associated with the current state container. The loopbounded by steps 768 and 778 is performed until there are no more BBSCsassociated with the current state container.

Upon a determination at step 768 that there are no more BBSCs associatedwith the current state container, control proceeds to step 780 of FIG.56B where a determination is made of whether or not upward_exposure hasbeen set to “yes”. If upward_exposure has been set to “yes”, controlproceeds to step 782 in which merge points are detected and merge pointdefinitions may be added by creating BBSCs.

An example of a merge point and the creation of a BBSC for a merge pointdefinition is discussed in following text in FIG. 57. Generally, if amerge point of multiple definitions is determined to be at a basic blockX containing no local references or definitions to the state container,a BBSC representing this merge point is created and associated with thebasic block X having the BBSC local summary information indicate “nolocal access”.

From step 782, control proceeds to step 784 where the next statecontainer is examined for the current routine. Control then proceeds tostep 760 where the loop bounded by step 760 and step 784 is repeateduntil a determination is made at step 760 that there are no more statecontainers associated with the current routine. Note that the use of theboolean upward_exposure in determining merge points provides advantagesover the method described in “Efficiently Computing Static SingleAssignment Form and the Control Dependence Graph”, by Ron Cytron et al.

The arrangement uses the boolean upward exposure to determine when anupwardly exposed definition has been detected within a basic block.Accordingly, merge points are only added when there is global access forreference outside of a basic block to a definition defined withinanother basic block. If there is no upward exposure, there can be noglobal connectivity even if there are definitions within a basic block.Thus, the steps of determining merge point definitions and adding neededBBSCs is′eliminated from the method.

Below in Appendix B is a pseudo-code description of the method of FIGS.55, 56A and 56B providing a more detailed description of performingglobal data flow analysis.

CREATION OF BBSC AT MERGE POINT DEFINITIONS

Referring now to FIG. 57, a global data flow analysis arrangement isillustrated in which a BBSC is produced while performing the foregoingglobal data flow analysis method. In this arrangement, the BBSC producedacts as a merge point definition for register “bx”, as in step 782 ofFIG. 56B. As previously represented in other figures, BBSCs associatedwith a basic block are enclosed within a rectangle. For example, BB0 609f is a rectangular box enclosing BBSC1 628 i. FIG. 57 includes five (5)basic blocks with appropriate global data flow edges GDF1-GDF3,respectively numbered 718 c-718 e and control flow edges CFE 1-CFE 5,respectively numbered 720 d-720 h. BB0 and BB2 both have write access toregister “bx”, as indicated in BBSC1 628 i and BBSC2 628 j. Thus, BBSC1and BBSC2 each provide a definition for the state container or register“bx” which is read in BB4, as indicated by BBSC 6281.

Using the foregoing method of FIG. 56A, 56B to create merge points,BBSC3 628 k is produced. BBSC3 represents a merge point definitionindicating the earliest control flow point within the current routine atwhich all dependent definitions merge. In this example, BBSC3 representsa merge point or juncture for two definitions of register “bx”. Mergepoints are used, for example, when performing optimization involvingdata dependency.

The foregoing arrangement for representing local and global data flowanalysis information has several advantages over existing arrangementstypically used for local and global data flow analysis information.

One advantage is that the hierarchical structure of the local and globaldata flow analysis information arrangement allows a clear and distinctline to be drawn between local and global data flow information in whichthe BBSC data structure acts as a wall or a filter between the local andglobal data flow. The data flow information arrangement provides anadvantage in software development and maintainence in that it is easy toidentify between data structures as effected by local data flow analysisand data structures as effected by global data flow analysis whenperforming, for example, a software modification. The fact that localand global data flow analysis information and their data structures canbe easily distinguished aids in debugging software affected by thesoftware modification. For example, if an incorrect value is stored to aBBV a developer may typically conclude that there is a coding errorwithin the local data flow analysis code and not the global data flowanalysis code.

The foregoing arrangement provides an information rich data structurewhich interconnects local and global data flow analysis informationwithout requiring a large amount of fixed storage as typically neededwhen using a bit vector. Additionally, the data flow analysisarrangement of the invention is scalable in that the amount of memorygenerally increases linearly with program size since the amount ofmemory used is linearly proportional to the number of definitions anduses within a program.

The foregoing arrangement also provides direct connectivity betweendefinitions and references both locally and globally. For example, for agiven basic block it can easily be determined what all of the globalreferences are.

Another advantage is that the foregoing arrangement does not use twodifferent techniques for representing local and global data flowanalysis information. Typically, the number of routines common to bothlocal and global data flow information will increase if both local andglobal data flow information impart similar structural features to theirrespective data structures and similar techniques are employed inbuilding and maintaining the data structures. Generally, an increase inthe amount of code commonly used for local and global data flow analysisresults in decreased development costs by typically reducing the amountof code which must be tested and maintained by developers.

The foregoing representation for data flow analysis information alsoaffords flexibility allowing an implementation to interchange andtrade-off optimization execution time for storage space. Recall suchflexibility is needed within a binary translator due to the differentoptimizations performed and their varying requirements as to systemmemory. For example, an optimization may be memory intensive. Uponcomputing local and global data flow analysis information, the localdata flow analysis information may be discarded if not needed inperforming the optimization, thus decreasing the amount of requiredmemory for storing data flow analysis information. Additionally, thehierarchical structure previously described provides for easilyidentifying what data structures comprise the local data flow analysisinformation that may be eliminated.

The foregoing methods described are flexible in that they can be usedwhen performing a binary translation without placing restrictions andmaking undue assumptions regarding the binary image.

TRANSLATORS AND OPTIMIZERS

As mentioned in conjunction with FIG. 4 the binary translator 54 is partof a background system 34 which also includes an optimizer 58. Thebackground system 34 is responsive to the non-native image file 17 b andprofile statistics gathered during a run-time execution of thenon-native image by a run-time system such as an interpreter 44.

Referring now to FIG. 58A, the binary image transformer 800 whichpreferably operates as a background process and transforms a non-nativebinary image from segment 17 b in conjunction with run-time profilestatistics from segment 17 d into a translated binary image 17 c isshown. The binary image transformer 800 comprises the translator 54 andthe optimizer 58 as depicted in the background system of FIG. 3. Thearrangement shown in FIG. 3 comprising an optimizer and a translator isone arrangement for the binary image transformer 800. Generally, thebinary image transformer transforms the first binary image or non-nativeimage 17 b to a translated binary image or native image 17 c.

FIG. 58B depicts another arrangement for the binary image transformer800 where the transformer comprises only the binary image translator 54with no optimizer. FIG. 58C depicts the arrangement for the binary imagetransformer of FIG. 3.

FIG. 58D depicts yet another alternate arrangement for the binary imagetransformer 800 comprising a binary image translator and optimizer 802as a combined unit. As an example of the binary image translator of FIG.58D, translation and optimization are intermixed to improve theefficiency of the translated/optimized code.

It is the arrangement as depicted in FIG. 58D which will now bedescribed in greater detail. Additionally, in the description thatfollows the first or non-native binary image 17 b is an image built toexecute in a complex instruction set computer (CISC). The translatedbinary image or native binary image 17 c is built to execute in areduced instruction set computer (RISC).

INTERMIXED TRANSLATION AND OPTIMIZATION

Referring now to FIG. 59, the steps performed by a binary imagetransformer 602 (FIG. 58D) to transform a binary image 17 b into atranslated binary image 17 c are depicted. Translation units aredetermined, as in step 804, as mentioned above in conjunction with FIGS.41 to 44. One of the translation units is selected, as in step 806. Atstep 808, a determination is made as to whether or not there are anyremaining translation units. If there are remaining translation units,control proceeds to step 810 where an initial intermediaterepresentation (IR) is produced. The initial IR is translated andoptimized to produce a final translation unit IR, as in step 812.Control is transferred back to step 806 where another translation unitis selected. Control proceeds to step 808 where a determination is againmade as to whether or not there are any remaining translation units.

If a determination is made, as in step 808, that there are no remainingtranslation units associated with the first binary image to betranslated, a final translated binary image IR is produced, as in step816. The final translated binary image IR combines individualtranslation unit IRs into one final translated binary image intermediaterepresentation (IR). Using the final translated binary image IR, thetranslated binary image 17 c is then produced, as in step 818.

Prior to performing optimizations or translations, it is necessary, asin step 804, to determine what translation units comprise the non-nativebinary image 17 b. Generally, to be able to perform a wide range ofoptimizations including local and global optimizations, it is necessaryto define a translation unit which does not inhibit the application ofexisting and new optimization techniques. One such preferred techniquefor determining a translation unit was previously described inconjunction with FIGS. 41 to 44.

SELECTING TRANSLATION UNITS

Referring now to FIG. 60, an embodiment 806 a of step 806 of FIG. 59 isshown in more detail. In technique 806 a selection of a translation unitbegins by determining for the image to be translated, call relationshipsamongst translation units, as in step 820. A call graph is producedusing the call execution order, as in step 822. A translation unit isselected from the call graph based on a depth first search of the callgraph, as in step 824.

Tracing the call execution order of the translation units comprising abinary image, as in step 820, includes tracing the run time executionorder in which translation units are called. For example, if routine Acalls routine B, and then routine B calls routine C, the call executionorder of these routines is A, B, C.

Referring now to FIG. 60A, an example of a call graph, as produced bystep 822 and used in step 824, is shown. The call graph produced as instep 822 represents the call execution order of step 820. Typically, acall graph is a data structure comprising nodes in which each nodecorresponds to a translation unit or routine called in the executionorder. In FIG. 60A, routine A calls routine B. In turn, routine B callsroutine C, D and E. Routine A also calls routine X. It can be seen thateach node in the graph corresponds to a routine. Nodes at a top level ofthe graph, such as node A 826, occur earlier in the execution order. Thebottom most level of the call graph contains the nodes representing thelast routines in the execution order, such as nodes 828 a-828 d.

In step 824 the depth first search of the graph as in FIG. 60A isperformed producing a depth first search order. One depth first searchproduces an ordering of nodes A, B, C, D, E and X. The order in whichthe translation units would be selected is in the order produced by thedepth first search.

One advantage of using the method described in FIG. 60 is that registerpreservation and allocation techniques can use the information producedby the call execution order. For example, a register allocator can usethe information that routine C does not call routine D, and the factthat both of these routines are called from routine B. A registerallocator determines that routines C and D have the same registersavailable for allocation within the routines.

Referring now to FIG. 61, another method 806 b for selecting atranslation unit is described. The method 806 b produces an ordering oftranslation units to be translated based on how frequently eachtranslation unit is called. As in step 830, the profile information isread. Specifically, the profile information includes information abouthow frequently translation units are called. As previously described,this profile information is run time execution information gathered bythe interpreter 44. Using the information from the profile statistics,the translation units are ordered from most to least frequently called,as in step 832. Each translation unit is selected from the ordering withthe most frequently called routine being selected first.

One benefit of using method 806 b is apparent when there is a userspecified time limit for translation. For example, if the user allotstime N to translate the first binary image to the second binary image,it is typically most beneficial in terms of run-time executionefficiency to translate, rather than interpret, those translation unitswhich are called or executed most frequently.

INITIAL INTERMEDIATE REPRESENTATION

Referring now to FIG. 62A, steps in a method for building an initial IR810 are shown. Memory operands of CISC instructions are removed andreplaced with register and constant operands, as in step 836. One CISCinstruction with memory operands produces one or more IR instructioncode cells in the initial IR. In step 838, an initial determination ismade as to whether the instruction or instructions which corresponds tothe IR instruction code cell can produce a run time exception.Information which is needed in later processing is also stored with eachIR instruction code cell. One piece of information which is stored andcan be used in later processing is the address of each instruction beingtranslated, as in step 840. Associated with each IR instruction codecell is the address of the corresponding machine instruction in thefirst binary image which corresponds to that IR instruction code cell.The address represents a location within the first binary image. Thisaddress is used, for example, when determining a correspondence betweena CISC instruction in a first binary image and IR code cells producingRISC instructions included in a second translated binary image. Alsoperformed at this time are tasks which initialize and create datastructures, for example, additional data structures included as part ofthe IR which are used in later processing stages. One such piece ofinformation which is stored and used in later processing isinitialization of condition code masks, as in step 842.

As previously mentioned, the implementation now being describedtranslates a first binary image comprising CISC instructions a secondbinary image comprising to RISC instructions. Therefore, some of thesteps that will be described to build the initial IR are particular tothe translation of CISC instructions to RISC instruction.

As to step 836, a CISC instruction typically includes a memory operandreferring to a memory location. RISC instructions generally do not havememory operands. Rather, RISC instructions load an address into aregister and retrieve contents from memory using the register as anaddress operand pointing to the memory location. In step 836, the memoryoperands are removed from instructions. These operands are replaced witha register or a constant value IR operand.

In step 838, an initial determination is made as to whether an IRinstruction code cell corresponds to a machine instruction that cangenerate a run-time exception. A run-time exception can occur, forexample, when there is a divide by zero error when executing a floatingpoint instruction. Another example of a run-time exception is when amemory access is attempted using an invalid address with a load or astore instruction. A data structure to maintain track of suchinstructions is described in conjunction with FIG. 62C.

Another piece of information which is associated with each IRinstruction code cell is recording the image address identifying alocation within the first binary image 17 b currently being translatedas in step 840.

Also associated with Each IR instruction code cell also includes acondition code bit mask, as provided in step 842. Generally, a CISCinstruction such as the X86 set mentioned above set condition codes toindicate certain conditions that happen as a result of run-timeexecution of an instruction. Typically a RISC architecture such as theAlpha architecture mentioned above, does not have or use conditioncodes. As a result, when translating CISC instructions to RISCinstructions, condition codes of the CISC instructions are handled asmentioned above in conjunction with FIGS. 7 to 20. When providing theinitial IR, a condition code bit mask is initialized and associated witheach IR instruction code cell for use in later condition codeprocessing.

The condition code bit mask associated with an IR code cell isinitialized indicating those condition codes which can be affected byexecution of an instruction corresponding to the IR code cell. Onerepresentation of the condition code bit mask reserves one bit in thebit mask for each condition code in the first instruction set associatedwith the binary image being translated.

Referring now to FIG. 62B, the initial IR corresponding to a CISCinstruction in a first binary image is shown. A CISC instruction 844ADDB is illustrated. ADDB adds together two bytes of information. Onebyte of information is in the register AL 844 a. The second operand is amemory location 844 b whose address is specified by adding the contentsof register SP (the stack pointer in the non-native architecture) plusregister AX plus 4. The add byte (ADDB) instruction loads the contentsfrom memory specified by address 844 b, adds a byte of that memorylocation to the contents of register AL 844 a, and stores the result inregister AL. In removing the memory operand in step 836, this CISCinstruction operating comprises 3 steps corresponding to 3 IRinstruction code cells which will now be described.

IR code cell 846 represents the formation of the address 844 b of thesecond operand. The address is stored in register tregl. The second IRinstruction code cell 848 loads from memory the contents of the locationspecified by tregl. The contents of the memory location are placed inregister treg2. Finally, the third IR instruction code cell 850 adds abyte of information from treg2 to register AL storing the result inregister AL. Thus, the IR instruction code cell 844 includes the addressformation of an operand corresponding to IR instruction code cell 846,loading the operand from memory corresponding to IR instruction codecell 848, and performing the data operation of the instruction 844,e.g., ADDB, in IR instruction code cell 850. Note that therepresentation in FIG. 62B is that the operands tregl and treg2 denotegeneral hardware registers that are allocated or more particularlydefined in a later register allocation process. At this point in thetranslation, the register operands tregl and treg2 operate as placeholders for which a particular register will be determined later in thetranslation. The original instruction in the first binary image beingtranslated 844 corresponds to 3 IR code cells and has an image address.The image address of the instruction 844 is associated with each of theIR instruction code cells 846, 848 and 850.

TRANSFORMER RUN-TIME EXCEPTION HANDLING

Referring now to FIG. 62C, a table 852 is shown which is used to keeptrack of initial run-time exception determinations. The table 852contains two columns. The first column 854 contains an entry for each IRinstruction that can be specified within an IR instruction code cell.The second column 856 contains an entry corresponding to an IRinstruction appearing in column 854. Column 856 contains a bit valueindicating whether a machine instruction, corresponding to an IRinstruction in column 854, when executed can produce a run timeexception. For example, the floating point add instruction (FADD) 854Acan produce a run time floating point exception as indicated by the bitvalue here “1” 856 a. A bit value is associated with each IR instructioncode cell.

The initial IR, which is built as a result of processing at step 810 ofFIG. 59, is an intermediate representation of the machine instructionscomprising the translation unit currently being processed. As previouslydiscussed, one IR comprises a list of IR instruction code cells. Each IRinstruction code cell comprises an IR instruction opcode followed by oneor more operands associated with that instruction opcode. In particular,the IR which is produced as a result of step 810 and used in theremaining translation and optimization steps is similar to the IRdiscussed in conjunction with two level data flow analysis. Differentportions of the IR are constructed during various portions of thetranslation and optimization steps. It is the IR construction of step810 which constructs an initial list of IR instruction code cellscorresponding to machine instructions comprising the translation unit.

As part of the initial IR processing of step 810, state containers areincorporated into the IR as needed to accurately represent IR operands.As previously described in conjunction with two level data flowanalysis, an IR state container is added to the IR for each piece ofstate information. Typically, as a result of initial processing in step810, state containers are added, for example, for each register, partialregister, and memory operand. As later processing steps are performed,the IR will be updated to accurately reflect the later processing steps.As an example, after partial register operands are replaced withregister operands, as will be described in register processing in step854 of FIG. 63, IR state containers and references to them areaccordingly updated to reflect the register processing.

Referring back to FIG. 59, after constructing an initial IR as in step810, the initial IR is translated and optimized to produce a finalroutine IR as in step 812.

Referring now to FIG. 63, details of the step 812 for translation andoptimization of the initial IR are set forth. Condition code processingis performed, as in step 852, to represent condition codes and theiruses into a form which readily transforms into RISC instructions of thetranslated binary image. Register processing is performed, as in step854. In particular, the Intel CISC instruction set includes partialregister operands which use a portion of a register as an operand.Special processing is needed to convert the partial register operand andtheir uses into a representation in the IR enabling translation intoRISC instructions.

Early optimization processing is performed, as in step 856. Whentranslating a particular CISC instruction set to a particular RISCinstruction set, it may be advantageous to perform some optimizationsteps prior to performing some translation steps in order to moreefficiently performed the later translation steps. A particularimplementation, as in step 856, performs early floating pointoptimization processing. This particular floating point optimizationprocessing includes performing peephole optimizations to reduce thenumber of IR instruction code cells used in later translation andoptimization steps. Another translation step, particular to translatingIntel CISC instructions to Alpha RISC instructions, includes processingthe Intel instructions which use floating point (FP) register stackaddressing, as in step 858.

In sum, the processing performed by step 852 through 858 of FIG. 63represents special processing particular to the CISC instruction setbeing translated, such as the Intel instruction set. An implementationwhich translates a different CISC instruction may use the same ordifferent processing step tailored for the CISC instruction setcomprising the binary image being translated. The processing performedby steps 852 through 858 typically work on translating and transformingthe IR including operands into a form which more closely resembles theRISC instruction set that will comprise the translated binary image 17 cproduced as a result of the binary image translation.

At step 860, local basic block and global routine optimizationprocessing is performed. Exception handler processing is performed, asin step 862, to enable proper handling of a run time exception whichoccurs when executing the translated binary image. The code selectionand operand processing, as in step 864, perform final transformation ofthe IR code cells. In particular, if the machine instruction setcomprising a binary image being translated 17 b has 32 bit operands andthe machine instruction set of the translated binary image 17 c has64-bit operands, part of the code selection processing insures that alloperands are 64 bits in length. If the entire set of IR opcodes includesopcodes which correspond to machine instructions in both the source anddestination instruction sets, code selection processing insures that noopcodes corresponding to machine instructions in the source instructionset of the binary image 17 b exist in the IR at the completion of step864.

The first code scheduling optimization pass, as in step 866, isperformed on the IR. At this point, the IR is generally in a one to onecorrespondence with instructions that will comprise the translatedbinary image. Optimizations, such as code scheduling which are highlydependent upon the machine instruction set of the translated binaryimage 17 c, are performed. Code scheduling typically rearrangessequences of instructions into a more optimal sequence due to resourcecontentions within the computer system 10.

Register allocation is performed, as in step 868. Register allocationdetermines specifically which registers within the machine instructionset comprising a translated binary image will be used to hold whatspecific operands. For example, recall that in the initial IRrepresentation, temporary registers such as tregl and treg2 wereintroduced when transforming a machine instruction from the binary image17 b into the initial IR. These temporary register names are nowassigned or bound to particular registers as used with the machineinstructions comprising the translated binary image 17 c.

A second code scheduling pass is performed, as in step 870. Afterallocating and binding a specific register to a certain operand, aparticular sequence of instructions may be able to be reordered for moreoptimal performance and efficient use of resources.

Exception handler tables are generated, as in step 872, and comprise thefinal translated binary image. These tables produced as a result of step872 enable proper run time behavior of the translated binary image whena run time exception occurs.

CONDITION CODE PROCESSING IN TRANSFORMER

Referring now to FIG. 64, condition code processing 852 of FIG. 63 isdescribed in more detail. Data flow analysis of the condition code bitmask is performed, as in step 874. The condition code bit masks arethose bit masks which were initialized and created as a result ofbuilding the initial IR in step 810 of FIG. 59. Data flow analysisincludes determining reads and writes, respectively references anddefinitions, to the various condition codes. Local data flow analysis isperformed for each basic block to determine “live” condition codes foreach basic block, as in step 876. A “live” condition code is one whichis defined in one basic block and referenced in another basic block. IRstate containers are provided one per condition code, as in step 878.State containers, which represent state information including conditioncodes, were previously discussed in conjunction with two level data flowanalysis and producing an initial IR, as in step 810. IR instructions,which set and propagate condition code values as in step 880, are added.

Referring now to FIG. 65A, a condition code bit mask 882 is shown. Thecondition code bit mask is a 32 bit register mask that is associatedwith each IR instruction code cell. In this illustration, a maximum of 8condition codes exist in the first machine instruction set comprisingthe non-native binary image 17 c. Four bytes of information 882 a-882 dcomprising the 32 bit mask are used to represent the four possiblestates of each condition code. Each condition code can be in one of fourstates as indicated by the corresponding byte in FIG. 65A: a “set” state882 a in which the condition code has been set due to the run timeexecution of an instruction, a “clear” state 882 b which indicates thatthis condition code cannot be set or is cleared by the execution of thismachine instruction, a “func” state 882 c in which the value isdetermined by the instruction results computed by the correspondingmachine instruction, and a fourth “undefined” state 882 d in which thevalue of the condition code as affected by this instruction cannot bedetermined.

As an example, a particular machine instruction within the non-nativebinary image 17 b can cause a condition code to be set to 1. Itscorresponding position within the set bit mask 882 a is set to 1.Similarly, if an operation performed by an IR code cell corresponds to amachine instruction whose result determines the condition code, a bitwithin the func bit mask 882 c which corresponds to the condition codewould be set to 1.

The condition code bit mask 882 is initialized, as in step 842 of FIG.62A when building the initial IR. After the initial IR has been built instep 810, the condition code bit mask associated with an IR instructioncode cell is initialized to indicate which condition codes can be setupon execution of the machine instruction associated with the IR opcode.

Step 874 of FIG. 64 examines the initialized condition code bit maskassociated with each instruction code cell and stores, for each basicblock, summary information indicating which condition codes are set inone block and referenced in other blocks. Such a condition code which isdefined in one block and referenced in succeeding block is referred toas a “live” condition code, as previously described.

In step 878 of FIG. 64, the IR is modified to contain state containersrepresenting each condition code. As previously described in conjunctionwith two level data flow analysis, a state container references a pieceof state information about a resource used in instructions. In theinstant case, CISC instructions are being translated into RISCinstructions where the RISC instructions only have immediate constantsand register operands. As a result, the state container which representsa condition code is used to map a condition code resource in a CISCinstruction to a register in the RISC architecture. Thus, the statecontainers act as resource map of a resource used in a first computersystem associated with the non-native binary image 17 b to anotherresource in a second computer system associated with the translated,native binary image 17 c.

As part of performing step 880, when an IR instruction code cell, suchas an add or subtract instruction, can set a condition code, other IRcode cells are added to set and propagate the proper condition code or,rather as in the instant case, the RISC register associated with thecondition code state container. IR instruction code cells are also addedwhere a condition code is referenced or read.

Referring now to FIG. 65B, a sample transformation of initial sourceinstructions to an IR after condition code (CC) processing will now bedescribed. Source instructions 884 are transformed into the initial IR886 by performing processing as in step 810. Condition code processing,as in step 852, is subsequently performed using the initial IR 886. TheIR resulting after condition code processing is represented as 888.Source instruction 884 a performs a byte compare of register AL to theconstant 3. Instruction 884 b performs a branch if the value containedin the register AL is not equal to 3. For the purposes of the example inFIG. 65B since the focus is on condition code processing, only thoseelements of the IR which are pertinent to condition code processing havebeen shown. For example, there is no target of the branch instruction884 b shown.

The initial IR produced as a result of processing source instructions884 is shown in 886. The first instruction 886 a of the initial IRsubtracts the value of register AL from the constant 3 storing theresult in a temporary register TZ. Additionally note 886 c indicatesthat a condition code in the condition code bit mask is set by thesubtract instruction. The IR instruction 886 b performs a conditionalbranch based on the condition code Z bit where the Z bit representswhether or not the operation previously performed as with the subtractinstruction 886 a produced a zero result.

The instructions shown in 886 are transformed after condition codeprocessing into the IR instruction code cells shown in 888. The firstinstruction 886 a has two corresponding instructions 888 a and 888 b.Since the target RISC instruction set only comprises a subtract quadword for integer values (SUBQ), the subtract byte instruction (SUBB) of886 a is replaced with a subtract quadword instruction of 888 a with theresult placed in a register denoted TZ. Although not shown in FIG. 65B,the IR comprises a state container associated with the Z bit conditioncode which corresponds to a register in the RISC architecture.

To maintain equivalency between the initial IR 886 and the IR aftercondition code processing 888, a byte is extracted from register TZ asperformed by instruction code cell 888 b, so that data operations areperformed upon a byte quantity as in the original source instruction andthe initial IR. The IR instruction code cell 886 b which performs a 32bit branch based on the Z bit condition code has been replaced with theIR instruction code cell 888 c which performs a 64-bit branch based onthe contents of the register associated with the Z bit condition codestate container.

FIG. 65B depicts a typical transformation of an initial IR 886 aftercondition code processing 888. The condition code in the CISCarchitecture is associated with a state container since the conditioncode is a piece of state information. In the translation that occurs inthe condition code processing, the state container associated with thecondition code is mapped to a register in the RISC architecture. Theresulting IR after condition code processing has the register in theRISC architecture associated with the condition code state container asan operand in the IR after condition code processing. Additionalinstructions, such as 888 b, are added to produce equivalent resultsbetween IR transformations. References and uses of the condition codeare replaced with the register state container associated with thecondition code. A state container is produced in the IR for eachcondition code. The state container maps the condition code, as with theZ bit condition code in this example, to a register in the RISCarchitecture, as denoted by the temporary register TZ. Within the IR,references to the Z bit will point to the state container and alldefinitions to the Z bit will point to the state container as well.

The transformation that occurs as a result of condition code processingenables the resulting IR to resemble machine instructions which willcomprise the translated binary image. Specifically in condition codeprocessing of step 852, CISC condition codes are mapped to RISCregisters. This mapping occurs using state containers. Additionally, newIR instruction code cells, such as 888 a-888 c have opcodes resemblingRISC machine instructions which will comprise the translated binaryimage.

Another type of processing which occurs when transforming CISCinstructions to RISC instructions in which the CISC instructions includepartial register operands is register processing, as performed in step854 of FIG. 63.

PARTIAL REGISTER OPERAND PROCESSING

Referring now to FIG. 66, steps performed for register processingtransforming the partial register operands are shown. At step 890 allpartial register operands are determined and replaced with acorresponding complete register operand. The complete register operandis a register operand as used in other instructions. Needed IRinstructions are added, as in step 892, producing a computational resultequivalent to the previous IR. At step 894, IR instruction code cellswhich reference a partial register operand is updated and replaced witha corresponding register operand.

Referring now to FIG. 67A, a diagram of partial register operands isshown. A 32-bit register EAX is shown 896. The entire register as anoperand in an instruction included in the first binary image is referredto as EAX. Partial register operands which appear in instructionsincluded in the binary image to be translated 17B are operands AH, ALand AX. AX as an operand refers to byte 0 and byte 1 of the contents ofregister EAX. The operand AH refers to byte 1 of register EAX andsimilarly the operand AL refers only to byte 0 of register EAX. Thepartial register operands for register EAX are AH, AL and AX. Whentranslating instructions from a first instruction set including partialregister operands to a second instruction set which does not includepartial register operands, each partial register operand is mapped to anentity included in the second instruction set. In the instant case CISCinstructions are translated to RISC instructions. The RISC instructionset only has registers or constant values as operands. Thus, eachpartial register operand is mapped to an entire register in the RISCarchitecture.

Referring now to FIG. 67B, an example is shown of how an initial IR istransformed after register processing. Specifically, an IR instructioncode cell 898 a is transformed into two corresponding code cells 898 band 898 c. IR instruction code cell 898 a performs byte addition ofpartial register operand AL with the contents of register tregl withresults stored in byte location AL. Additionally, condition codes areset by this instruction, as indicated by the “CC” of 898B. Registerprocessing replaces partial register operand AL of instruction 898 awith two equivalent instructions 898 b and 898 c, as indicated in FIG.67B. Partial register AL of 898 a is replaced with EAX, as in 898 b and898 c. IR instruction code cell 898 b adds the contents of registertregl to register EAX storing the result in register treg2. IRinstruction code cell 898 c inserts a byte into register EAX from treg2and stored the result in register EAX. IR instruction code cell 898 cpreserves the data compatability of register EAX in that only a byte ofthe data register is replaced. FIG. 67B is an example once again of howthe partial register operand AH is replaced with the full registeroperand EAX and how additional instructions are added to preserve theoperation result of the original instruction.

FLOATING POINT OPTIMIZATION

Floating point optimization processing, as depicted in step 856, ispeephole optimization processing performed early in the overalltranslation and optimization process. As it is known in the art,peephole optimization processing replaces one or more instructions fromone instruction set with one or more instructions which are deemed to bemore efficient. In the instant case, the one or more instructionsreplaced are CISC instructions. The peephole optimization replaces theCISC instructions with an equivalent single RISC instruction which willcomprise the final translated image. The peephole optimizationprocessing, as depicted in step 856, is highly dependent upon theinstruction set.

Referring now to FIG. 68A, a code pattern 902 comprising multipleinstructions is shown. This code pattern is searched for in the IRinstructions and replaced with an equivalent RISC instruction.Specifically, the pattern depicted in 902 comprises four differentinstructions which must appear in sequence. For simplicity, only thoseopcodes and relevant operands used in identifying the code pattern areshown in 902 of FIG. 68A. Entries 902 a to 902 d correspond to IRinstruction code cells which appear in sequence within the IR.Instruction 902 a compares a floating point value stored as the topstack value with the constant 0. Typically, the stack is an area ofmemory pointed to by a register (stack register). Stack operands areimplicit operands in the floating point (FP) Intel CISC instructions.The address of one of the implicit operands is indicated by the addressin the stack register. Operands are pushed (added) onto the stack andpopped (removed) from the stack as FP operations are performed.

When the CISC machine instruction which corresponds to the IRinstruction code cell 902 a is executed, certain bits in the status wordregister are set. Instruction 902 b stores the status word of the 16 bitfloating point state information to a register (denoted <REG> in FIGS.68A-68B). Instruction 902 c performs a test of the register to which thestatus word was stored by comparing the register to a bit maskspecifying a comparison value. A branch is performed by instruction 902d based upon the content of the status word as compared to the bit mask.

Instructions 902 a-902 d perform a conditional branch based on thefloating point value stored on top of the stack. Note that the lastinstruction 902 d which will be searched for in the pattern can eitherbe a branch on equal to zero (BEQ), or a branch not equal to zero (BNE).The RISC instruction set to which the series of CISC instructions isbeing translated comprises a floating point branch operation as a singleinstruction. Thus, the result of the four CISC instructions isaccomplished with one equivalent replacement instruction in the RISCarchitecture.

The precise instruction which replaces instructions 902 a-902 d dependsupon several items in the code pattern 902, as shown in FIG. 68B.

REPLACEMENT INSTRUCTIONS

Referring now to FIG. 68B, a table 903 is shown depicting a replacementinstruction 908 which replaces a detected pattern 902 a-902 d. Theprecise replacement instruction shown as 908 depends upon the bit maskvalue 904, as used in instruction 902 c, and the last instruction in thecode pattern 906, as used in instruction 902 d. For example, assume th ebit mask value used in instruction 902 c tests for the Z bit and thelast instruction in 902 d is a branch if equal to 0 instruction (BEQ).The Z bit is set in the CISC instruction if a zero data value isindicated by the FTST instruction 902 a. The replacement instruction isthe FBEQ instruction having an operand that corresponds to the registerused in 902 b and 902 c. The replacement instructions included in column908 have a one to one correspondence with a RISC instruction that willcomprise the translated or native binary image 17 c.

Several things should be noted about the floating point optimizationprocessing being performed early in the translation and optimization ofthe first binary image 17 b. Applying this optimization to the IRprovides a transformation which results in a replacement IR instructionhaving a direct correspondence to a machine instruction that willcomprise the translated binary image. Thus, early in processing elementsof the IR have a direct correlation to the translated binary image 17 c.

The IR used in this translation and optimization processing has aparticular structure which provides great flexibility in thatoptimization and translation substeps can be intermixed and performed inan efficient order without undue restrictions. For example, the IR hasthe property that the opcode of any instruction code cell is one of: anopcode which corresponding to the non-native instruction set of thenon-native image 17 b, a pseudo op instruction specifically included fortranslation processing, or an opcode corresponding to a machineinstruction in the destination or native instruction set of the nativebinary image 17 c. Given this property, an optimization such as theearly floating point peephole optimization processing of step 856 can beperformed at multiple points during binary translation producing aresulting replacement instruction in the IR which has a directcorrespondence to an instruction in the translated binary image 17 c.

Typically, in a compiler several different IR are used rather than asingle IR as here. In a compiler an initial IR goes through severaltransformations into other IRs in which each IR has varying propertiesand restrictions from the previous IR representation. Generally, theseproperties restrict the type of processing, e.g., translation andoptimization steps, which can occur at various phases of translation orcompilation. For example, within a compiler there is a compiler frontend performing syntactic and semantic processing and a compiler back endwhich typically performs optimizations and code generations. The frontend produces an initial IR which is input to the back end. The back endinitially produces a compact intermediate representation therebylimiting or restricting the number of IR opcodes which it must analyze.The optimizer then transforms the compact intermediate representationand produces an optimized intermediate representation. The codegenerator subsequently generates a final intermediate representationfrom the optimized intermediate representation. The final intermediaterepresentation has the property that its opcodes correspond directly toinstructions in the destination instruction set. If an opcode that istypically included in the final intermediate representation appeared inthe foregoing compact intermediate representation, an error intranslation results. Given this typical organization of a compiler withthe foregoing restrictions, the compiler itself is generally unable tointerchange optimization steps with translation steps due to processingrestrictions. The binary translator of the invention does not imposesuch undue restrictions on the IR. Thus, the binary translator canperform substeps of optimization and translation in an efficient orderwithout undue restrictions.

Using a single IR in binary translation, rather than multiple IRs, as inthe compiler described above, is generally a good design choice due tothe nature of the transformation which occurs in the binary translation.In a binary translation, low-level machine instructions are transformedinto other low-level machine instructions. In a compilation, high-levelsource code is transformed into low-level machine instructions. Thesource code is “high-level” relative to the machine instructions. In thebinary translation, there is generally no transformation or mapping ofhigh level language constructs to low-level machine instructions and asingle IR suffices. Rather, as in compilation, transformation ofhigh-level source code typically includes several repeatedtransformations of a higher level structure into a corresponding lowerlevel structure to produce low-level machine instructions.

Step 858 of FIG. 63 performs floating point (FP) register stackaddressing processing. The CISC instruction set in binary image 17 bincludes floating point instructions having implicit operands on thestack. The stack was previously discussed in conjunction with early FPpeephole optimization processing. The RISC instruction set does not haveimplicit stack operand instructions. Thus, as with the partial registeroperand, the CISC instructions performing floating point register stackaddressing must be transformed into an equivalent item in the RISCinstruction set. Following is an example of four IR instruction codecells corresponding to CISC instructions to be translated:

1 FLD EA1 /*push EA1 on stack */ 2 FLD EA2 /*push EA2 on stack */ 3FADDP /*add two top stack elements, push  result */ 4 FST EA3 /* storeresult in EA3 */

The first of the foregoing instructions loads or pushes the firstoperand register EA1's contents onto the stack. Similarly, the secondinstruction also pushes the content of operand register EA2 onto thestack placing the content in a memory location indicated by the addressin the stack register. The third instruction performs a floating pointadd (FADDP) and pushes the result of the floating point addition ontothe stack. The effect of the FADDP instruction is that the two operandsEA1 and EA2 previously pushed on the stack are popped off, and replacedwith an arithmetic result that is a single floating point number. Thefourth instruction FST stores the result from the stack placing it inEA3. The fourth instruction pops the top value off of the stackreturning the stack to its original position prior to the foregoingsequence of four instructions. The stack is an implicit operand in eachof these four instructions. The Alpha RISC instruction set, associatedwith the translated image 17 c, does not have similar floating pointregister stack addressing operands or equivalent instructions.

One translation technique makes explicit the implicit stack operand andsubstitutes, for the stack operand, an equivalent register in the RISCarchitecture. Later processing steps ensure that the replacementinstruction opcode corresponds to a RISC instruction rather than performa direct replacement within this translation step.

SECONDARY OPTIMIZATION AND TRANSLATION

After performing steps 852 through 858, the IR is considered to bewell-formed in that peculiarities particular to the CISC instructionset, such as implicit FP stack operands, partial register operands, andcondition codes, have been removed. After completion of step 858 of FIG.63, the IR resembles a series of RISC instructions. Specifically, IRoperands are register operands or constants. There are no more memoryoperands. Additionally, when possible, added instructions, for example,as a result of condition code processing or register processing, areeither pseudo instructions or closely resemble the RISC instructionsthat will comprise the translated binary image 17 c. When possible,steps 852 through 858 of a preferred implementation do not add opcodesor replace existing opcodes with other opcodes having a directcorrelation to the binary image 17 b currently being translated.

Referring now to FIG. 69, steps comprising local basic block and globalroutine optimization processing 860 are set forth. Typically, thoseoptimizations which are performed per basic block are referred to aslocal optimizations, and those optimizations which are performed asbetween basic blocks are referred to as global optimizations.

Local peephole optimizations are performed, as in step 910. Aspreviously mentioned a peephole optimization searches for a particularpattern or sequence of instructions and replaces those instructions withother instructions deemed to be more efficient. Previously, a peepholetechnique was applied to translations of step 856 performing floatingpoint optimization processing. However, as used at step 856, thepeephole technique accomplishes more than an optimization. In step 856,the peephole technique is used for translating a series of CISCinstructions to a single RISC instruction. At step 910, the focus isoptimization processing because of the prior translation steps alreadyperformed.

As in step 912, common subexpression elimination (CSE) is performed perbasic block. In common subexpression elimination a subexpression isidentified which produces a result. This subexpression is used multipletimes within the translation unit or program. The optimization generallyidentifies the common subexpression, computes its result in onestatement, and rather than use the entire expression in repeatedlocations, substitutes each repeated occurrence of the subexpressionwith the result as computed by the first statement.

Dead code elimination is performed for the translation unit, as in step914. Dead code elimination involves identifying and removing thosesegments of code which can never be reached as by a section of codewhich is always branched around or has no entry point.

As in step 916, constant propagation is performed for a translationunit. Constant propagation typically involves operations with constants.One use of constant propagation, for example, is in the computation ofaddresses of subscripted variables when the subscript values can bedetermined earlier at compile time. As in step 918, inlining isperformed for the translation unit. The inlining optimization of step918 replaces a call to a routine, for example, with the instructionscomprising the routine. The instructions of the routine are included inline rather than the call to the routine.

At this point in processing, a preferred implementation, as in step 920,repeats local optimization 910 processing and dead code elimination 912.Repeating certain optimizations can be beneficial in that repeating anearlier optimization can result in a better IR that has subsequentlybeen effected by a later optimization. For example, repeating localpeephole optimization, as in step 910, can be beneficial becauseadditional code has been included as a result of inlining as in step918. The specific optimizations which an implementation chooses toperform is highly dependent upon the IR representation and the previoustranslations and transformations which have occurred.

Additionally, it should be noted that the two level data flow dataanalysis technique previously can be used in performing the local andglobal routine optimization processing of step 860.

As in step 862, a substep of translation and optimization processing isexception handler processing. As previously discussed when building theinitial IR, as in step 810, an initial determination was made as towhether or not an instruction is capable of generating a run timeexception. Each IR instruction was previously examined in step 810 and adetermination was made as to whether a corresponding machineinstruction, if executed, could generate a run time exception. In thisprior processing the determination was made solely by examining the IRopcode. A translator can more specifically determine if an exception canoccur by examining the associated operands. For example, if aninstruction is capable of generating only a memory access exception andthe operand address is indicated by the stack pointer which is alwaysknown to point to a valid memory address, this instruction will notgenerate a memory access violation or exception at run time. Therefore,a further determination is made that even though the particular opcodeitself is capable of generating an exception, using the specificoperands of a particular instruction code cell, a memory exception isnot generated. This step is generally a refinement of the previousprocessing determinations made in the initial IR processing of step 810.

CODE SELECTION AND OPERAND PROCESSING

Referring now to FIG. 70 code selection and operand processing (step 864of FIG. 63) is set forth in detail. Generally, the code selection andoperand processing perform remaining transformations needed to place IRinstruction opcodes and operands in a direct correspondence with machineinstructions that comprise the instruction set of the architecture ofthe computer system 10 and hence provide the native image 17 c. As instep 922, any remaining source IR instruction opcodes are replaced withtarget IR instruction opcodes. A source IR instruction opcode has adirect correspondence with a machine instruction in the binary image 17b. In this step, remaining source instruction opcodes are replaced withone or more equivalent instruction opcodes each having a directcorrespondence with a machine instruction in the second instruction setassociated with the translated binary image 17 c. For example, if theRISC architecture comprises only 64-bit length instructions performing64 bit data operations, after completing step 864, each of the IRinstruction code cells correspond to a 64 bit length instructionperforming a 64 bit data operation.

Step 922 can be accomplished using a pattern driven instruction look-upand replacement technique using a table which maps a source instructionopcode to one or more corresponding target IR instruction opcodes. As instep 924, when translating a CISC operand to a RISC operand, the RISCarchitecture requires that the 32-bit CISC operands be transformed tocorresponding 64-bit RISC operands. Additionally, in this specifictranslation, the high order 32 bits of each corresponding 64-bit RISCoperand are sign extended. This processing step uses local data flow andglobal data flow information, as can be determined using the two leveldata flow analysis technique, to locate definitions and uses of operandsto determine if a particular operand has been properly sign extended. Asin step 926 intra image call processing is performed. An intra imagecall is a call made from one translation unit to another translationunit wherein both translation units are within the binary image beingtranslated 17 b.

Step 928 is performed as a “catch all” step performing any remainingmiscellaneous processing necessary to remove source dependencies fromthe IR placing the IR in a final routine form such that no opcodesincluded in an IR instruction code cell have a direct correspondence toan instruction in the non-native binary image 17 b. The IR in finalroutine form produced as a result of step 928 comprises IR instructioncode cells which correspond directly to machine instructions associatedwith the instruction set of the computer system 10 to provide nativebinary image 17 c.

INTRA-IMAGE CALL PROCESSING

Referring now to FIG. 70A, the steps of performing intra image callprocessing are set forth. As in step 930, a determination is made as towhether a call is an intra image call (YES decision) or an inter imagecall (NO decision). An inter image call performs a call to a routine inanother translation unit. An intra-image call is a call from onetranslation unit or routine to another routine within the same binaryimage being translated.

If a determination is made at step 930 that the current call is aninterimage call, run time intervention is required by the run timeinterpreter to transfer control to the called routine. As such, there isno special processing performed with the current call. Control proceedsto step 932 and the next call is examined.

If a determination is made at step 930 that the current call is an intraimage call, control proceeds to step 934. At step 934 provisions aremade for direct run time execution transfer to the called translationunit. For example, one type of call is a PC (program counter) relativecall in which the address of the called routine is represented bydisplacement relative to the instruction currently being executed. Theeffective address of the called routine is formed by adding the run timeaddress of a program counter register plus and offset. The programcounter register contains the address of the instruction following thecall instruction. The offset represents a byte displacement. The binaryimage translator and optimizer 802 determine a correct translateddisplacement value for the called routine within the native binary image17 c.

Using the binary image address associated with the CISC callinstruction, as in step 840, and the displacement comprising the CISCcall instruction, a first target address within the non-native binaryimage 17 b corresponding to the called routine is determined. Thetranslator and optimizer 802 map the addresses of the CISC callinstruction and the called routine within the binary image 17 b,respectively, to first and second translated addresses within thetranslated binary image 17 c. By determining the difference betweenthese two translated addresses, the translated displacement isdetermined representing the displacement between the calling instructionand the called routine in the translated binary image 17 c.Modifications are made to the IR code cell corresponding to the callinstruction by including the translated displacement value.

After completing step 934, control proceeds to step 936 where the nextcall is examined. Processing resumes with step 930.

In step 872 of FIG. 63, exception handler tables are generated toprovide for proper run time control if an instruction in the translatedbinary image when executed generates a run time exception. Referring nowto FIG. 71A, a diagram of a translated binary image 17 c and itscorresponding non-native binary image 17 b are shown. The non-nativeimage 17 b has a floating point add (FADD) instruction 938. The binaryimage translator and optimizer 802 produce an equivalent instructionADDT 940 in the translated binary image 17 c. When executed, thetranslated instructions 940 can produce a run time exception, such as afloating point divide by 0 error, depending on the operand values atrun-time. An exception handler is typically invoked when such a run-timecondition occurs. The translated binary image 17 c includes userexception handler tables 942 and translated exception tables 944. Theuser exception handler table 942 identifies a user routine address orhandler to which control is transferred when a run-time exception occurswithin a user routine or translation unit. The translator exceptiontable 944 is used by the binary translation run-time system when anexception occurs as will be explained in following text. The translatorexception table 944 comprises one or more table entries.

Referring now to FIG. 71B, a diagram of the table entry for thetranslator exception table is shown. The table entry within thetranslator exception table 944 includes a first binary image address 946a, a count field 946 b followed by one or more pairs of a CISC resource946 c and a corresponding RISC resource 946 d. The first binary imageaddress 946 a corresponds to an address within the image 17 b. The countfield 946 b indicates the number of resource pairs 946 c to 946 d thatfollow. The pairs of resource entries 946 c and 946 d identify,respectively, a CISC resource and a corresponding RISC resource. Theseentries are used at run time as will be described in conjunction withFIG. 71C.

Referring now to FIG. 71C the run time transfer of control when a runtime exception occurs is shown. For example, a run time exception canoccur when executing a translated binary image 17 c, as with the ADDTinstruction 940. At this point run time control passes to a standardportion of the operating system such as the RISC handler 948. The RISChandler reads the user exception handler tables 942 to obtain theaddress of a user specified handler to which run time control istransferred. The RISC handler 948 reads an address identifying atranslator run time handler routine 950. The translator run time handler950 is included as part of the binary translation system. The binaryimage translator and optimizer 802, when generating a translated binaryimage 17 c, place the address of the translator run time handler routine950 in the user exception handler table included in the translatedbinary image 17 c. The user exception handler table is typically astandard part of an object file format of the translated binary image.

The translator run time handler routine 950 is a special routineincluded as part of the binary image translator. The translator run timehandler 950 uses the information contained in the translator exceptiontable 944 to map a RISC resource as included in the non-native binaryimage 17 c to a CISC resource. The translator run time handler 950transfers control to the appropriate CISC exception handler 952. At thispoint control transfers to the run-time system 32 to determine if theCISC exception handler 952 is translated, or if the run time interpretermust be invoked to execute the CISC exception handler 952.

TRANSLATOR-OPTIMIZER SUMMARY

The foregoing steps of optimization and translation are performed on aper translation unit basis. During the transformation from the initialIR produced in step 810 to the final binary image IR produced as aresult of step 816, the intermediate data structures created and used bythe binary image translator and optimizer 802 typically use a largeamount of memory and additional computer system resources. To performthe translation and optimization upon the entire translation unit,rather than translate one translation unit at a time as in FIG. 63,would require a large amount of memory for the binary image translatorand optimizer 802.

In summary, the steps of performing translation and optimization, as setforth in FIG. 63, and their particular order, as performed within abinary image transformer 800, are particularly dependent upon theinstruction set of the non-native binary image 17 b and the othermachine instruction set of the translated binary image 17 c. Forexample, special processing steps 852 through 858 are highly dependentupon the source instruction set used in the binary image 17 b.

Additionally, other optimization and translation steps, such as step856, which performs floating point optimization processing is highlydependent upon the instruction sets of both the non-native binary image17 b and the translated binary image 17 c. The particular optimizationsteps and their respective order included, as in step 860, willtypically vary with implementation enabling production of an efficientlyexecuting binary translated image 17 c.

An embodiment of the binary image transformer 800 may have only aportion of the planned functionality implemented and can still be usedin binary translation. When the binary image transformer is underdevelopment, for example, a portion of the background translator andoptimizer 802 may not be implemented. For example, one implementation ofthe binary image transformer does not perform processing for a floatingpoint instruction in the CISC instruction set. As a result, the nativebinary image 17 c does not comprise any translated floating pointinstructions. As a result, when executing the native binary image 17 c,the run-time system always provides for interpretation of floating pointinstructions and control passed to the run-time interpreter for theseinstructions. Additionally, the binary image transformer containsspecial processing to ignore floating point instructions during thetranslation process. Such instructions would then be interpreted.

The foregoing techniques described for translation and optimization of abinary image affords a new and flexible way to perform translation andoptimization of a binary image. Additionally, the technique is efficientin its use of computer system resources.

The foregoing technique is flexible in that the steps of op timizationand translation can be intermixed and performed in a variety ofdifferent orderings. The intermediate representation affords thisflexibility by not imposing undue restrictions or making assumptionsabout the state of an intermediate representation at various pointsduring translation and optimization.

Using the foregoing intermediate representation decreases developmentand maintenance costs associated with a binary translation process. Theforegoing single intermediate representation used throughout the binarytranslation process is a single IR having opcodes corresponding to bothsource and destination instruction sets. Since a single IR is usedthroughout the translation process, common service routines operating onthe IR can be used throughout the binary translation process ascontrasted with a more costly binary translation process having variousIRs requiring multiple corresponding sets of service routines operatingon the various IRs.

Having described preferred embodiments of the invention, it will nowbecome apparent to those of skill in the art that other embodimentsincorporating its concepts may be provided. It is felt therefore thatthis invention should not be limited to the disclosed embodiments butrather should be limited only by the spirit and scope of the appendedclaims.

What is claimed is:
 1. A method executed in a computer system forperforming data flow analysis, the method comprising the steps of: A.performing local data flow analysis upon one or more basic blocks of aroutine, each of said basic blocks representing a sequence of one ormore instructions with no intervening entry or exit point, said localdata flow analysis producing local data flow analysis information foreach of said basic blocks describing data access of a state containerwithin each of said basic blocks; B. for each of the basic blocks of theroutine: (i) determining upwardly exposed data references of statecontainers which are upwardly exposed to definitions of said respectivestate containers defined in the other said basic blocks, the upwardlyexposed data references being dependent upon the definitions of saidstate containers in said other basic blocks, each state containerrepresenting a piece of state information alterable by one or more ofsaid definitions, and (ii) producing, from said determination, localdata flow analysis summary information for each state container accessedby the basic block; and C. performing, using only the produced localdata flow analysis summary information, global data flow analysiscomprising the step of: determining merge points and addingcorresponding merge point definitions to a list of definitions for theroutine only when it has been determined from the local data flowanalysis summary information that there is, in a first basic block, adata reference of a state container upwardly exposed to a definition, ina second basic block, of said state container, each of said merge pointsbeing a joining definition point within said routine for multipledefinitions of said state container, wherein said local data flowanalysis information includes summary information, and the step ofdetermining merge points and adding merge point definitions of saidroutine further comprises the steps of creating a list of definitionsfor said routine using said summary information from said step ofperforming said local data flow analysis, determining if there is atleast one upwardly exposed data reference of a state container usingsaid summary information, and in response to said determining stepadding merge point definitions corresponding to said merge points usingsaid list of definitions, including creating one or more basic blockstate containers, each of said one or more basic block state containersrepresenting an artificial definition of a state container, each of saidone or more basic block state containers being associated with acorresponding basic block and an associated state container anddescribing how said associated state container is accessed in saidcorresponding basic block, said artificial definition of an associatedstate container representing merging definitions for said associatedstate container in which said corresponding basic block contains nolocal references and definitions of said associated state container. 2.The method of claim 1 wherein said method is performed upon anintermediate representation of said routine, said intermediaterepresentation including one or more codecells each representing a unitof operation corresponding a portion of said routine.
 3. The method ofclaim 2 wherein said data flow analysis method is performed by a binarytranslator optimizing machine instructions of a first computerarchitecture being translated to other machine instructions of a secondcomputer architecture, said intermediate representation initiallycomprising code cells each representing a machine instruction in saidfirst computer architecture, said intermediate representation translatedto a final representation comprising code cells each representinganother instruction in said second computer architecture.
 4. The methodof claim 3 further comprising the step of: producing said intermediaterepresentation using an opcode table, each of said code cells includesan opcode field and one or more operand fields, said opcode fieldcomprising a value from said opcode table representing one of: a sourcemachine instruction of said first computer architecture, a targetmachine instruction of said second computer architecture, or apseudo-instruction in neither said first or said second computerarchitecture.
 5. The method of claim 2 wherein said data flow analysismethod is performed by an optimizing compiler optimizing an intermediaterepresentation of a source program, said optimizing compiler comprisinga compiler front end and a compiler back end, said compiler front endproducing said intermediate representation that is optimized by saidcompiler back end producing machine instructions.
 6. The method of claim1, wherein said local analysis information includes summary information,and the method includes the step of: storing said summary information ina basic block state container, said basic block state container beingassociated with a corresponding basic block and an associated statecontainer and describing how said associated state container is accessedin said corresponding basic block.
 7. The method of claim 1, whereindata access of a state container within a basic block is one of fourpatterns: a first pattern comprising read and write access or aread-modify-write access, within the basic block, of the statecontainer; a second pattern comprising only read access, within thebasic block, of the state container; a third pattern comprising noaccess, within the basic block, of the state container; and a fourthpattern comprising only write access, within the basic block, of thestate container.
 8. A computer apparatus for storing data flow analysisinformation comprising: an intermediate representation of a processorroutine, the processor routine comprising one or more basic blocks, eachof said basic blocks comprising one or more instructions with nointervening entry or exit point, and the intermediate representationcomprising one or more basic block data structures, each basic blockdata structure being associated with one of the basic blocks, and eachbasic block data structure being associated with a sequence of one ormore code cells representing the one or more instructions of theassociated basic block, each code cell comprising an opcode and one ormore operands; a state container for holding state information alterableby one or more instructions in the routine; one or more basic blockvalues for storing local data flow analysis information, wherein each ofsaid basic block values represents a unique data value accessed within abasic block associated with said state container, and wherein an operandof one of said code cells is said state container, said operand beingassociated with one of said basic block values of said state container;and a basic block state container associated with said state container,said basic block, and said one or more basic block values, said basicblock state container comprising local data flow analysis summaryinformation describing how said state container is accessed within saidbasic block, and global data flow analysis information produced by aglobal data flow analysis, such that a global data value definition ofsaid state container, defined within a first basic block by a first codecell and globally referenced in a second basic block by a second codecell, is represented in the global data flow analysis information as afirst basic block value associated with a first basic block statecontainer, said second code cell reference to said global data valuedefinition being represented as a second basic block value having upwardexposed read dependency of the definition supplied in said first basicblock value as described in local data flow analysis summary informationassociated with the first and second basic block state containers, saidsecond basic block value being associated with a second basic blockstate container that is associated with said first basic block statecontainer, such that all local data flow analysis summary informationabout a basic block needed for global data flow analysis is obtained byexamining only the basic block state containers associated with a basicblock and only local data flow analysis summary information is used toperform the global data flow analysis such that local data flow analysisinformation is substantially independent from global data flow analysisinformation.
 9. The memory of claim 8 wherein said state information isrepresented by said state container is one of: a register, a portion ofmemory, or a condition code.
 10. The memory of claim 8 wherein controlflow edges represent basic block control flow within said routine. 11.The memory of claim 8 further comprising an opcode table includingvalues representing opcodes used in said codecells, each value in saidopcode table representing one of a source machine instruction in a firstcomputer architecture, a target machine instruction in a second computerarchitecture, or a pseudo-instruction neither in said first or saidsecond computer architecture.
 12. The memory of claim 8 wherein each ofsaid basic block values corresponds to a basic block value datastructure comprising: a read list head field associated with an operandwhich is the first operand within a basic block associated with saidbasic block value to read a data value associated with saidcorresponding basic block value; a definition field associated with anoperand which defines said data value; a basic block state containerfield associated with a basic block state container associated with astate container; a modify write boolean field set to true when thedefinition for said data value results from a read-modify write access;a read_modify pointer field identifies an operand, if any, whichperforms a read and a destructive write operation to said statecontainer; and a basic block value next field associated with anotherbasic block values data structure corresponding to another one of saidbasic block values.
 13. The memory of claim 8 wherein each of said basicblock state containers correspond to a basic block state container datastructure comprising: a use list head field, used in global data flowanalysis, identifying global data references to a data value defined ina basic block associated with said basic block state container, each ofsaid global data references being made in another basic block; a definelist head field, used in global data flow analysis, identifying globaldata definitions, each of said global data definitions being read withinsaid corresponding basic block and defined in anther basic block; astate container field identifying a state container; a basic block valuelist head field identifying basic block values associated with saidstate container; a basic block pointer associated with a basic blockdata structure identifying said corresponding basic block; a basic blocksummary information field describing how basic block values within saidcorresponding basic block access said state container; and a next basicblock state container field identifying another basic block statecontainer associated with said state container.
 14. The memory of claim13 wherein said basic block summary information field indicates one of:read indicating that only read access are performed within saidcorresponding basic block; write indicating that the first use of saidstate container within said corresponding basic block is a write access;read_write indicating that a read access is performed within saidcorresponding basic block that is dependent upon a global definitionwithin another of said basic blocks; read_modify_write indicating thatall definitions within said corresponding basic block are read-modifywrite accesses; and no_access indicating that said state container isnot accessed within said corresponding basic block.
 15. The memory ofclaim 8 wherein a basic block data structure corresponds to one of saidbasic blocks and further comprises: an instruction forward fieldassociated with a first codecell included in said corresponding basicblock; an instruction backward field associated with a last codecellincluded in said corresponding basic block; a basic block statecontainer head pointer field associated with basic block statecontainers of said corresponding basic block; an inward control flowedge list identifying incoming control flow edges from other basicblocks indicating those basic blocks that preceed said correspondingbasic block in control flow; and an outward control flow edge listidentifying outgoing control flow edges to other basic blocks from thecorresponding basic block, each of said outward control flow edgesidentifying a basic block that follows said corresponding basic block incontrol flow.